本文整理汇总了C#中ModelBuilder.ForSqlServerUseIdentityColumns方法的典型用法代码示例。如果您正苦于以下问题:C# ModelBuilder.ForSqlServerUseIdentityColumns方法的具体用法?C# ModelBuilder.ForSqlServerUseIdentityColumns怎么用?C# ModelBuilder.ForSqlServerUseIdentityColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelBuilder
的用法示例。
在下文中一共展示了ModelBuilder.ForSqlServerUseIdentityColumns方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnModelCreating
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Force the server to update the ID
modelBuilder.ForSqlServerUseIdentityColumns();
}
示例2: OnModelCreating
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.ForSqlServerUseIdentityColumns();
modelBuilder.Entity<Order_Detail>(entityBuilder =>
{
entityBuilder.Property(e => e.UnitPrice).HasColumnType("money");
entityBuilder.HasKey(e => new
{
K1 = e.OrderID,
K2 = e.ProductID,
});
});
modelBuilder.Entity<Shipper>(entityBuilder =>
{
entityBuilder.HasMany(e => e.Orders)
.WithOne(e => e.Shipper)
.HasForeignKey(e => e.ShipVia)
.IsRequired(false);
});
modelBuilder.Entity<Order>(entityBuilder =>
{
entityBuilder.HasMany(e => e.Order_Details).WithOne(e => e.Order)
.IsRequired()
.HasForeignKey(e => e.OrderID).OnDelete(DeleteBehavior.Restrict);
});
modelBuilder.Entity<Product>(entityBuilder =>
{
entityBuilder.HasMany(e => e.Order_Details)
.WithOne(e => e.Product)
.IsRequired()
.HasForeignKey(e => e.ProductID)
.OnDelete(DeleteBehavior.Restrict);
});
// TODO GitHubIssue#57: Complete EF7 to EDM model mapping
// ToTable() for navigation configuration is not yet supported in EF7, remove following ignores after it's ready.
modelBuilder.Entity<Customer>().Ignore(e => e.CustomerDemographics);
modelBuilder.Entity<CustomerDemographic>().Ignore(e => e.Customers);
modelBuilder.Entity<Employee>().Ignore(e => e.Territories);
modelBuilder.Entity<Territory>().Ignore(e => e.Employees);
}
示例3: OnModelCreating
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.ForSqlServerUseIdentityColumns();
builder.Entity<CompleteItem>(e =>
{
e.ToTable("CompleteItems");
e.HasKey(i => i.CompleteItemID);
});
builder.Entity<FieldTypeMeta>(e =>
{
e.ToTable("FieldTypeMeta");
e.HasKey(i => i.FieldTypeMetaID);
e.Property(i => i.FieldTypeMetaID).UseSqlServerIdentityColumn();
});
builder.Entity<AuditLog>(e =>
{
e.ToTable("AuditLog");
e.HasKey(i => i.AuditLogID);
e.Property(i => i.AuditLogID).UseSqlServerIdentityColumn();
});
builder.Entity<Item>(e =>
{
e.ToTable("Items");
e.HasKey(i => i.ItemID);
e.Property(i => i.ItemID).UseSqlServerIdentityColumn();
e.HasMany(i => i.Entities)
.WithOne(en => en.Item)
.HasForeignKey(en => en.ItemID);
});
builder.Entity<Lookup>(l =>
{
l.ToTable("Lookups");
l.HasKey(e => e.LookupID);
l.Property(e => e.LookupID).UseSqlServerIdentityColumn();
l.HasOne<Field>().WithOne(e => e.Lookup).HasForeignKey<Field>(e => e.ValueLookup);
l.HasOne(i => i.LookupType).WithMany(e => e.Lookups).HasForeignKey(e => e.LookupTypeID);
l.HasOne<Lookup>().WithOne(e => e.Parent).HasForeignKey<Lookup>(e => e.ParentID);
});
builder.Entity<LookupType>(lt =>
{
lt.ToTable("LookupTypes");
lt.HasKey(e => e.LookupTypeID);
lt.Property(l => l.LookupTypeID).UseSqlServerIdentityColumn();
});
builder.Entity<Entity>(e =>
{
e.ToTable("Entities");
e.HasKey(en => en.EntityID);
e.Property(en => en.EntityID).UseSqlServerIdentityColumn();
e.HasMany(en => en.EntityFields)
.WithOne(ef => ef.Entity)
.HasForeignKey(ef => ef.EntityID);
});
builder.Entity<Field>(e =>
{
e.ToTable("Fields");
e.HasKey(ef => ef.FieldID);
e.Property(ef => ef.FieldID).UseSqlServerIdentityColumn();
});
builder.Entity<ItemType>(e =>
{
e.ToTable("ItemTypes");
e.HasKey(it => it.ItemTypeID);
e.Property(it => it.ItemTypeID).UseSqlServerIdentityColumn();
});
builder.Entity<EntityType>(e =>
{
//.........这里部分代码省略.........