本文整理汇总了C#中ModelBuilder类的典型用法代码示例。如果您正苦于以下问题:C# ModelBuilder类的具体用法?C# ModelBuilder怎么用?C# ModelBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModelBuilder类属于命名空间,在下文中一共展示了ModelBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnModelCreating
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
{
relationship.DeleteBehavior = DeleteBehavior.Restrict;
}
}
示例2: OnModelCreating
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<KettleChips>()
.Property(e => e.BestBuyDate)
.StoreGeneratedPattern(StoreGeneratedPattern.Identity)
.DefaultValue(new DateTime(2035, 9, 25));
}
示例3: OnModelCreating
public override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<CustomerOrderHistory>().HasKey(coh => coh.ProductName);
modelBuilder.Entity<MostExpensiveProduct>().HasKey(mep => mep.TenMostExpensiveProducts);
}
示例4: OnModelCreating
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<LpaUser>(e =>
{
e.Key(p => p.Id);
e.Property(p => p.Id).UseSqlServerSequenceHiLo("LpaUserSeq", "dbo");
e.Property(p => p.Username).MaxLength(120).Required();
e.Property(p => p.Password).MaxLength(150).Required();
e.Property(p => p.PasswordSalt).MaxLength(100).Required();
e.Property(p => p.Created).Required().ValueGeneratedNever().HasSqlServerDefaultValueSql("sysdatetime()");
e.Collection(p => p.Claims).InverseReference(p => p.User);
e.ToSqlServerTable("Users");
});
modelBuilder.Entity<LpaUserClaim>(e =>
{
e.Key(p=>new { p.UserId, p.ClaimId }).SqlServerClustered();
e.Reference(p => p.Claim).InverseCollection(p => p.Users).Required();
e.Reference(p => p.User).InverseCollection(p => p.Claims).Required();
e.ToSqlServerTable("UserClaims");
});
modelBuilder.Entity<LpaClaim>(e =>
{
e.Key(p => p.Id).SqlServerClustered();
e.Property(p => p.Name).MaxLength(125).Required();
e.Property(p => p.Value).MaxLength(150).Required();
e.Collection(p => p.Users).InverseReference(p => p.Claim);
e.ToSqlServerTable("Claims");
});
}
示例5: BuildModel
public override void BuildModel(ModelBuilder builder)
{
builder
.Annotation("ProductVersion", "7.0.0-beta6-13815");
builder.Entity("EF7ProjectLemon.Auth", b =>
{
b.Property<int>("AuthId")
.ValueGeneratedOnAdd();
b.Property<string>("Login");
b.Key("AuthId");
});
builder.Entity("EF7ProjectLemon.Person", b =>
{
b.Property<int>("PersonId")
.ValueGeneratedOnAdd();
b.Property<string>("Name");
b.Key("PersonId");
});
}
示例6: CreateModel
protected Model CreateModel()
{
var modelBuilder = new ModelBuilder(new ConventionSet());
modelBuilder.Entity<MappingQueryTestBase.MappedCustomer>(e =>
{
e.Key(c => c.CustomerID);
e.Property(c => c.CompanyName2).Metadata.Relational().Column = "Broken";
e.Metadata.Relational().Table = "Broken";
if (!string.IsNullOrEmpty(DatabaseSchema))
{
e.Metadata.Relational().Schema = "wrong";
}
});
modelBuilder.Entity<MappingQueryTestBase.MappedEmployee>(e =>
{
e.Key(em => em.EmployeeID);
e.Property(em => em.City2).Metadata.Relational().Column = "City";
e.Metadata.Relational().Table = "Employees";
e.Metadata.Relational().Schema = DatabaseSchema;
});
modelBuilder.Entity<MappingQueryTestBase.MappedOrder>(e =>
{
e.Key(o => o.OrderID);
e.Property(em => em.ShipVia2).Metadata.Relational().Column = "ShipVia";
e.Metadata.Relational().Table = "Orders";
e.Metadata.Relational().Schema = DatabaseSchema;
});
OnModelCreating(modelBuilder);
return modelBuilder.Model;
}
示例7: BuildModel
public override void BuildModel(ModelBuilder builder)
{
builder
.Annotation("ProductVersion", "7.0.0-beta6-13815");
builder.Entity("OoadProjekatBaza.RestoranBaza.Models.Restoran", b =>
{
b.Property<int>("RestoranId")
.ValueGeneratedOnAdd();
b.Property<float>("GeoDuzina");
b.Property<float>("GeoSirina");
b.Property<string>("Naziv");
b.Property<string>("Opis");
b.Property<float>("Rating");
b.Property<byte[]>("Slika")
.Annotation("Relational:ColumnType", "image");
b.Property<string>("Telefon");
b.Property<string>("fourSqaureId");
b.Key("RestoranId");
});
}
示例8: OnModelCreating
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Make Blog.Url required
modelBuilder.Entity<Blog>()
.Property(b => b.Url)
.IsRequired();
}
示例9: BuildModel
protected override void BuildModel(ModelBuilder modelBuilder)
{
modelBuilder
.Annotation("ProductVersion", "7.0.0-beta8-15964")
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("PhoneSpotter.Models.PhoneSpotting", b =>
{
b.Property<int>("PhoneSpottingId")
.ValueGeneratedOnAdd();
b.Property<double>("Latitude");
b.Property<double>("Longitude");
b.Property<string>("Notes");
b.Property<string>("PhoneManufacturer");
b.Property<string>("PhoneModel");
b.Property<DateTime>("SpotTime");
b.HasKey("PhoneSpottingId");
});
}
示例10: BuildTargetModel
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "7.0.0-beta8-15964")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Dorothy.Models.Guest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("AdultCount");
b.Property<int>("ChildCount");
b.Property<string>("Group");
b.Property<bool>("HasEmail");
b.Property<bool>("HasInvitation");
b.Property<bool>("IsOptional");
b.Property<string>("Names");
b.Property<string>("Notes");
b.HasKey("Id");
});
}
示例11: OnModelCreating
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Parent>()
.HasMany(b => b.Children)
.WithOne(b => b.MyParent)
.HasForeignKey(b => b.ParentId);
}
示例12: BuildModel
protected override void BuildModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.0.1");
modelBuilder.Entity("cloudscribe.Core.IdentityServer.EFCore.Entities.PersistedGrant", b =>
{
b.Property<string>("Key");
b.Property<string>("Type");
b.Property<string>("ClientId")
.IsRequired()
.HasAnnotation("MaxLength", 200);
b.Property<DateTime>("CreationTime");
b.Property<string>("Data")
.IsRequired();
b.Property<DateTime>("Expiration");
b.Property<string>("SiteId")
.IsRequired()
.HasAnnotation("MaxLength", 36);
b.Property<string>("SubjectId");
b.HasKey("Key", "Type");
b.HasIndex("SiteId");
b.ToTable("csids_PersistedGrants");
});
}
示例13: BuildModel
protected override void BuildModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.0.0-rc2-20901");
modelBuilder.Entity("LinkThere.Models.Link", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("ClickCount")
.IsConcurrencyToken();
b.Property<string>("Key")
.IsRequired();
b.Property<string>("LinkUrl")
.IsRequired();
b.HasKey("Id");
b.HasIndex("Key")
.IsUnique();
b.ToTable("Links");
});
}
示例14: RegisterModels
public void RegisterModels(ModelBuilder modelbuilder)
{
modelbuilder.Entity<Dictionary>(etb =>
{
etb.HasKey(e => e.Id);
etb.Property(e => e.Id).UseSqlServerIdentityColumn();
etb.ForSqlServerToTable("Dictionaries");
}
);
modelbuilder.Entity<Culture>(etb =>
{
etb.HasKey(e => e.Id);
etb.Property(e => e.Id).UseSqlServerIdentityColumn();
etb.ForSqlServerToTable("Cultures");
}
);
modelbuilder.Entity<Localization>(etb =>
{
etb.HasKey(e => e.Id);
etb.Property(e => e.Id).UseSqlServerIdentityColumn();
etb.ForSqlServerToTable("Localizations");
}
);
}
示例15: BuildTargetModel
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.1.0-rtm-22752")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Domain.Bag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Description");
b.Property<string>("Factory");
b.Property<string>("ImageLink");
b.Property<string>("Name");
b.Property<string>("Owner");
b.Property<int>("Price");
b.Property<DateTime?>("TimeBought");
b.Property<DateTime>("TimeCreation");
b.HasKey("Id");
b.ToTable("Bags");
});
}