ef-code-first

Entity Framework 6 Code First migrations - multiple branches for production

一笑奈何 提交于 2020-02-01 15:32:33
问题 In my project we have a branch model that has a separate development branch and has a separate branch for each release. It may look like this: dev ______ ______ / \ / \ master --+---+----+---+---+----+----+--- (...) r1 \______/ r2 \_______/ So we develop on dev merge it to master and then we create a release branch (r1, r2, ...). We want to use EF 6 (manual not automatic) migrations but we have a question that we don't know how to answer. Imagine this: dev _(1)__ ____(4) / \ / \ master --+---

Entity Framework 6 Code First migrations - multiple branches for production

蹲街弑〆低调 提交于 2020-02-01 15:31:06
问题 In my project we have a branch model that has a separate development branch and has a separate branch for each release. It may look like this: dev ______ ______ / \ / \ master --+---+----+---+---+----+----+--- (...) r1 \______/ r2 \_______/ So we develop on dev merge it to master and then we create a release branch (r1, r2, ...). We want to use EF 6 (manual not automatic) migrations but we have a question that we don't know how to answer. Imagine this: dev _(1)__ ____(4) / \ / \ master --+---

How to generalise access to DbSet<TEntity> members of a DbContext?

旧街凉风 提交于 2020-02-01 03:37:09
问题 I have a DbContext with several of the following type of members: public DbSet<JobLevel> JobLevels { get; set; } public DbSet<Country> Countries { get; set; } public DbSet<Race> Races { get; set; } public DbSet<Language> Languages { get; set; } public DbSet<Title> Titles { get; set; } All these are where T: IdNamePairBase , which has Id and Name members only. I am trying desperately to find a common interface with which to access any of these members, to generalise the following MVC3

EF Code First: Retrieving a base type queries all derived type tables

安稳与你 提交于 2020-01-30 06:49:27
问题 I'm having an odd issue with EF 4.1 Code First where even though I have configured an entity to generate columns for its inherited properties, it still joins to the inherited type's table. Here are my classes: public class Human { public int Id { get; set; } public string Name { get; set; } } public class SuperHuman : Human { public int Id { get; set; } public string Powers { get; set; } } public class MarvelDbContext : DbContext { public DbSet<Human> Humans { get; set; } public DbSet

EF Code First: Retrieving a base type queries all derived type tables

試著忘記壹切 提交于 2020-01-30 06:48:26
问题 I'm having an odd issue with EF 4.1 Code First where even though I have configured an entity to generate columns for its inherited properties, it still joins to the inherited type's table. Here are my classes: public class Human { public int Id { get; set; } public string Name { get; set; } } public class SuperHuman : Human { public int Id { get; set; } public string Powers { get; set; } } public class MarvelDbContext : DbContext { public DbSet<Human> Humans { get; set; } public DbSet

Implementing Zero Or One to Zero Or One relationship in EF Code first by Fluent API

别来无恙 提交于 2020-01-26 08:46:35
问题 I have two POCO classes public class Order { int id; string code; int? quotationId; //it is foreign key public int Id{get;set;} public string Code{get;set;} public int? QuotationId{get;set;} Quotation quotation; public virtual Quotation Quotation { get; set; } .... } public class Quotation { int Id; string Code; public int Id{get;set;} public string Code{get;set;} Order order; public virtual Order Order { get; set; } .... } each Order may made from one or zero quotation, and each quotation

Implementing Zero Or One to Zero Or One relationship in EF Code first by Fluent API

青春壹個敷衍的年華 提交于 2020-01-26 08:46:07
问题 I have two POCO classes public class Order { int id; string code; int? quotationId; //it is foreign key public int Id{get;set;} public string Code{get;set;} public int? QuotationId{get;set;} Quotation quotation; public virtual Quotation Quotation { get; set; } .... } public class Quotation { int Id; string Code; public int Id{get;set;} public string Code{get;set;} Order order; public virtual Order Order { get; set; } .... } each Order may made from one or zero quotation, and each quotation

One to one relationship with FK in one direction

痞子三分冷 提交于 2020-01-25 04:19:15
问题 How do I get the following relationship to only generate the FK in Entity2? public class Entity1 { public int Id { get; set; } public virtual Entity2 Entity2 { get; set; } } public class Entity2 { public int Id { get; set; } public int? Entity1Id { get; set; } public virtual Entity1 Entity1 { get; set; } } I want Entity1 be able to get a reference to an Entity2 (have EF lazy load it), but I don't want Entity1 to have an FK to Entity2 in the db, I just want Entity2 to have an FK to Entity1. Is

Can I specify child entity default ordering with Entity Framework Code First?

▼魔方 西西 提交于 2020-01-25 03:20:42
问题 For example, with the following classes public class Child { public Guid Id { get; set; } public String Description { get; set; } public double Value { get; set; } public Child() { Id = Guid.NewGuid(); } } public class Parent { public Guid Id { get; set; } public String Name { get; set; } public virtual IList<Child> Children { get; set; } public Parent() { Id = Guid.NewGuid(); Children = new List<Child>(); } } And context public class TempContext : DbContext { public DbSet<Child> Children {

Two Foreign Keys in entity framework for same table

此生再无相见时 提交于 2020-01-25 00:07:14
问题 I have two entities: Municipality and RoadSemgents. Municipality is parent and RoadSegments is a child table. I need to have two foreign Keys in RoadSegments from the same table (Municipality). public class Municipality { [Key] public int ID { get; set; } public string Name { get; set; } } public class RoadSegments { [Key] public int ID { get; set; } //ForeignKeys public int CodeMunicipalityLeft_ID { get; set; } public int CodeMunicipalityRight_ID { get; set; } [ForeignKey(