不久,我想在我的表上创建复合键,保留主键,以提高sql server搜索性能.每当我搜索没有主键的实体(即一串GUID)时,性能问题就会发生在200k数据表上.假设我有3个班级
public class Device{
public int ID { get; set; }
public string UDID { get; set; }
public string ApplicationKey { get; set; }
public string PlatformKey { get; set; }
public ICollection<NotificationMessageDevice> DeviceMessages { get; set; }
}
public class NotificationMessageDevice {
[Column(Order = 0), Key, ForeignKey("NotificationMessage")]
public int NotificationMessage_ID { get; set; }
[Column(Order = 1), Key, ForeignKey("Device")]
public int Device_ID { get; set; }
public virtual Device Device { get; set; }
public virtual NotificationMessage …Run Code Online (Sandbox Code Playgroud) 我正在使用Entity Framework Codefirst来创建我的数据库.当我通过ODBC连接到它时,具有模式名称dbo.pk_Jobs的默认主键似乎扰乱了访问2007.如果我手动编辑名称并删除模式名称并将此主键重命名为pk_jobs,则Access现在可以读取该表.
是否可以使用Fluent Api,数据属性或任何其他方法指定主键名称不包括架构的名称.
public class ReportsContext : DbContext
{
public DbSet<Job> Jobs { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Job>().ToTable("Jobs");
modelBuilder.Entity<Job>().HasKey(j => j.uuid);
base.OnModelCreating(modelBuilder);
}
}
public class Job
{
public Guid uuid{ get; set; }
public int active{ get; set; }
}
Run Code Online (Sandbox Code Playgroud) 我有一个表(Id,name,itemst,otherproperties),Id是主键,我想要一个唯一的复合键(name,itemst).如何使用代码首先通过流畅的API(首选)或注释添加此代码?
我在 SQLite 的 Ef 核心模型中有这个类定义。
public class Ejercicios : BaseModel
{
private int _TipoEjercicio;
[Key]
public int TipoEjercicio
{
get { return _TipoEjercicio; }
set { SetProperty(ref _TipoEjercicio, value); }
}
private string _DescripcionEjercicio;
public string DescripcionEjercicio
{
get { return _DescripcionEjercicio; }
set { SetProperty(ref _DescripcionEjercicio, value); }
}
private string _HexForeColor;
public string HexForeColor
{
get { return _HexForeColor; }
set { SetProperty(ref _HexForeColor, value); }
}
private string _HexBackGroundColor;
public string HexBackGroundColor
{
get { return _HexBackGroundColor; …Run Code Online (Sandbox Code Playgroud) System.InvalidOperationException: The instance of entity type 'ProjectAssignment' cannot be tracked because another instance with the same key value for {'ProjectID'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(TKey key, InternalEntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.St
Run Code Online (Sandbox Code Playgroud)
我制作了一个带有Worker(ID和其他列)和Project(ID和其他列)Entity和ProjectAssignment(许多ID分配给许多Workers)的项目。但是,当我尝试获取ProjectAssignment数据时,会出现Application Insights中的错误。奇怪的是,该ID并未更早出现。
这是https://github.com/Streamc/ContosoObserve1/tree/master/Proj_s
context.Database.EnsureCreated();
var ProjectAssignments = new ProjectAssignment[]
{
new ProjectAssignment
{
ProjectID = Projects.Single( i => i.ID == 1).ID,
WorkerID …Run Code Online (Sandbox Code Playgroud)