fluent-entity-framework

Mapping foreign key in HasOptional().WithOptionalDependent() relation in Entity Framework 6

狂风中的少年 提交于 2019-12-19 05:15:22
问题 I have the following data-model in Entity Framework 6.1.3: using System.Data.Entity; public class Student { public int Id { get; set; } public virtual Contact Contact { get; set; } } public class Contact { public int Id { get; set; } public virtual Student Student { get; set; } } public class MyContext : DbContext { protected override void OnModelCreating(DbModelBuilder builder) { builder.Entity<Contact>() .HasOptional(x => x.Student) .WithOptionalDependent(x => x.Contact)

Is there an EF6 DbContext Generator for C# which uses Fluent API?

落爺英雄遲暮 提交于 2019-12-09 07:12:53
问题 I know that the EF6 VS Tools for Visual Studio 2012 come with a T4 template to generate DbContext classes which work with EF6. But I want to have a generator which uses fluent API. The older version I used with EF4 and EF5 don't work with EF6 and the author no longer works on them to make them EF6 compatible. Is anyone else working on a generator which uses Fluent API which works with EF6? 回答1: http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d If you have a

EF Core fluent mapping to inner object properties

核能气质少年 提交于 2019-12-07 04:38:23
问题 I have a class that contains some properties. For some architectural reasons, I have an instance of another objet into my class. Simple example public class MyEntity { public MySubEntity SubEntity {get; set;} } For this, I create fluent mapping like : builder.ToTable(MyEntity.CONST_TABLE_NAME); builder.HasKey(m => m.Id); builder.Property(m => m.Column1).IsRequired(); builder.Property(m => m.SubEntity.Column2).IsRequired(); I cannot integrate all my subEntity properties into my main entity (my

EF Core fluent mapping to inner object properties

丶灬走出姿态 提交于 2019-12-05 09:55:48
I have a class that contains some properties. For some architectural reasons, I have an instance of another objet into my class. Simple example public class MyEntity { public MySubEntity SubEntity {get; set;} } For this, I create fluent mapping like : builder.ToTable(MyEntity.CONST_TABLE_NAME); builder.HasKey(m => m.Id); builder.Property(m => m.Column1).IsRequired(); builder.Property(m => m.SubEntity.Column2).IsRequired(); I cannot integrate all my subEntity properties into my main entity (my subEntity has its own intelligence). I just want to map my subentity properties, which is NOT stored

Is there an EF6 DbContext Generator for C# which uses Fluent API?

这一生的挚爱 提交于 2019-12-03 09:20:03
I know that the EF6 VS Tools for Visual Studio 2012 come with a T4 template to generate DbContext classes which work with EF6. But I want to have a generator which uses fluent API. The older version I used with EF4 and EF5 don't work with EF6 and the author no longer works on them to make them EF6 compatible. Is anyone else working on a generator which uses Fluent API which works with EF6? http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d If you have a database you can use reverse code first it will generate all your fluent api mapping. 来源: https:/

One to zero-or-one with HasForeignKey

☆樱花仙子☆ 提交于 2019-11-28 17:29:49
I have two models: public class Person { public virtual int Id { get; set; } public virtual Employee Employee { get; set; } // optional } public class Employee { public virtual int Id { get; set; } public virtual int PersonId { get; set; } public virtual Person Person {get; set; } // required } public class EmployeeConfiguration : EntityTypeConfiguration<Employee> { public EmployeeConfiguration() { Property(e=>e.PersonId) // I need this property mapped .HasColumnName("person_id") .HasColumnType("int"); } } I want to map them using fluent mapping. Employee table has column 'person_id' which is

One to zero-or-one with HasForeignKey

末鹿安然 提交于 2019-11-27 10:31:18
问题 I have two models: public class Person { public virtual int Id { get; set; } public virtual Employee Employee { get; set; } // optional } public class Employee { public virtual int Id { get; set; } public virtual int PersonId { get; set; } public virtual Person Person {get; set; } // required } public class EmployeeConfiguration : EntityTypeConfiguration<Employee> { public EmployeeConfiguration() { Property(e=>e.PersonId) // I need this property mapped .HasColumnName("person_id")