ef-fluent-api

Use IEntityTypeConfiguration with a base entity

廉价感情. 提交于 2020-04-07 19:07:49
问题 In EF Core 2.0, we have the ability to derive from IEntityTypeConfiguration for cleaner Fluent API mappings (source). How can I extend this pattern to utilize a base entity? In the example below, how can I have a BaseEntityConfiguration to reduce duplication in LanguageConfiguration and MaintainerConfiguration , modifying properties that are in the BaseEntity only in the BaseEntityConfiguration ? What would such a BaseEntityConfiguration look like; and how would it be used, if at all, in

Define Entity Framework relationships using foreign keys only by FluentAPI

拜拜、爱过 提交于 2020-03-19 07:58:13
问题 Is any way of defining Entity Framework relations using foreign keys only (no virtual properties of reference type) with FluentAPI (data models should not be changed)? CardDataModel public class CardDataModel { public int CardId { get; set; } } CheckItemDataModel public class CheckItemDataModel { public int CheckItemId { get; set; } public int CardId { get; set; } } 回答1: Yes, it's possible in EF Core. It wasn't in EF6 and below, but now EF Core provides parameterless overloads of HasMany /

One-to-One relationships in Entity Framework 7 Code First

▼魔方 西西 提交于 2020-01-22 12:03:28
问题 How to configure One-to-One or ZeroOrOne-to-One relationships in Entity Framework 7 Code First using Data Annotations or Fluent Api? 回答1: You can define OneToOne relationship using Fluent API in Entity Framework 7 as below class MyContext : DbContext { public DbSet<Blog> Blogs { get; set; } public DbSet<BlogImage> BlogImages { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Blog>() .HasOne(p => p.BlogImage) .WithOne(i => i.Blog)

One-to-One relationships in Entity Framework 7 Code First

狂风中的少年 提交于 2020-01-22 12:02:44
问题 How to configure One-to-One or ZeroOrOne-to-One relationships in Entity Framework 7 Code First using Data Annotations or Fluent Api? 回答1: You can define OneToOne relationship using Fluent API in Entity Framework 7 as below class MyContext : DbContext { public DbSet<Blog> Blogs { get; set; } public DbSet<BlogImage> BlogImages { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Blog>() .HasOne(p => p.BlogImage) .WithOne(i => i.Blog)

One-to-One relationships in Entity Framework 7 Code First

旧巷老猫 提交于 2020-01-22 12:02:28
问题 How to configure One-to-One or ZeroOrOne-to-One relationships in Entity Framework 7 Code First using Data Annotations or Fluent Api? 回答1: You can define OneToOne relationship using Fluent API in Entity Framework 7 as below class MyContext : DbContext { public DbSet<Blog> Blogs { get; set; } public DbSet<BlogImage> BlogImages { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Blog>() .HasOne(p => p.BlogImage) .WithOne(i => i.Blog)

Possible to set column ordering in Entity Framework

≡放荡痞女 提交于 2020-01-22 08:18:36
问题 Is there any possible configuration to set database column ordering in entity framework code first approach..? All of my entity set should have some common fields for keeping recordinfo public DateTime CreatedAt { get; set; } public int CreatedBy { get; set; } public DateTime ModifiedAt { get; set; } public int ModifiedBy { get; set; } public bool IsDeleted { get; set; } I want to keep this fields at the end of the table. Is there any possible EF configuration that i can use to config this

c#, Is it possible to define databinding from sqlite database to c# object typesave?

旧巷老猫 提交于 2020-01-15 10:52:27
问题 I have the following class hirarchy: public class A { public string A_string; public int A_int; public double A_double; public B BInstance; } public class B { public string B_string; public int B_int; public double B_double; public C CInstance; } public class C { public string C_string; public int C_int; public double C_double; } and need a mapping to the following database values: +--------------+-----------+--------------+---------------------+-------------------+----------------------+----

c#, Is it possible to define databinding from sqlite database to c# object typesave?

倾然丶 夕夏残阳落幕 提交于 2020-01-15 10:51:22
问题 I have the following class hirarchy: public class A { public string A_string; public int A_int; public double A_double; public B BInstance; } public class B { public string B_string; public int B_int; public double B_double; public C CInstance; } public class C { public string C_string; public int C_int; public double C_double; } and need a mapping to the following database values: +--------------+-----------+--------------+---------------------+-------------------+----------------------+----

Entity Framework 6 Code First on SQL Server: Map “bool” to “numeric(1,0)” instead of “bit”

北城以北 提交于 2020-01-15 10:26:09
问题 Forward warning #0: upgrading to EF core is not an option in the near future. Forward warning #1: I can't change the column type to bit because this could potentially break legacy VB apps that employ the very same db I'm developing a new app for. Forward warning #2: I also can't employ the int property ==> hidden bool property approach because the very same model needs to work when targeting an Oracle database (in Oracle decimal(1,0) does indeed get mapped to bool without issues - I need to

Entity Framework 6 Code First on SQL Server: Map “bool” to “numeric(1,0)” instead of “bit”

此生再无相见时 提交于 2020-01-15 10:25:08
问题 Forward warning #0: upgrading to EF core is not an option in the near future. Forward warning #1: I can't change the column type to bit because this could potentially break legacy VB apps that employ the very same db I'm developing a new app for. Forward warning #2: I also can't employ the int property ==> hidden bool property approach because the very same model needs to work when targeting an Oracle database (in Oracle decimal(1,0) does indeed get mapped to bool without issues - I need to