ef-code-first

EF CF: many-to-many relation with additional info

会有一股神秘感。 提交于 2019-12-07 14:08:28
问题 We have legacy database and we map the new objects and props to the old tables and columns. So far so good. We have many-to-many relation which was mapped successfully. The intermediate table contains additional data. When we try to map the intermediate table to an object we get exception that the mapping is already defined. If we remove mapping from any side of the relation we get error that table is missing (ofc, we expect just that). I can do that easily with NHibernate and I am starting

Is inheritance of navigation properties supported?

牧云@^-^@ 提交于 2019-12-07 13:44:46
问题 Having difficulty finding relevant search results... Given this model: public abstract class A { public int ID { get; set; } public int CustomerID { get; set; } public virtual Customer Customer { get; set; } } public class B : A { } public class C : A { } public class Customer { public int ID { get; set; } public virtual ICollection<B> Bs { get; set; } public virtual ICollection<C> Cs { get; set; } } With this configuration: protected override void OnModelCreating(DbModelBuilder modelBuilder)

.net mvc razor dropdowns for foreign keys

我的梦境 提交于 2019-12-07 13:42:31
Ok, this seemed simple, but is making my head spin. I have created models based on CodeFirst. public class Category { public int ID { get; set; } [StringLength(255, MinimumLength = 1)] public string Name { get; set; } } public class SubCategory { public int ID { get; set; } public Category category { get; set; } [StringLength(255, MinimumLength = 1)] public string Name { get; set; } } Now when i auto-generate the controller and view for SubCategory it (out-of-the-box) lets me create new SubCategory objects without specifying the Category (even through it correctly creates a foreign key

Bounded Contexts and EF Code First - How to put them together?

你。 提交于 2019-12-07 13:42:12
问题 IMHO, one of the most brilliant DDD concept is the ability of separate contexts in a application. But I'm confused on how I can put everything to work together. First, I know that one thing is not related to other. But my question falls exactly on the Infrastructure/ORM part. For example, I have a domain object called Procedure (a medical procedure). In the Context of Registration , only thing that matters is Code and Name . But in Procedure Management Context , I have a lot of other fields

MVC3 - how to link a newly created child object to its parent?

☆樱花仙子☆ 提交于 2019-12-07 13:40:00
问题 I am a complete novice at MVC, and can't seem to get my head around a very basic concept. I have a parent object, that contains a collection of child objects. I want to create a new child object, and link it to the parent object, persisted in the database via EF4 public class Parent { public int Id { get; set; } public string Name { get; set; } public virtual List<Child> Children { get; set; } } So far, what happens in my very basic application is this. My user goes to a page displaying the

Entity Framework Snapshot History

拥有回忆 提交于 2019-12-07 13:33:23
问题 I am trying to figure out how to use Code First Entity Framework and keep a snapshot history of certain tables. This means that for each table I want to track, I would like to have a duplicate table postfixed _History. Every time I make a change to a tracked table row, the data from the database is copied to the history table before the new data is saved to the original table, with a Version column that gets incremented. So imagine I have a table called Record. I have a row (ID:1,Name:One

POCO classes and ViewModels in MVC3

时光怂恿深爱的人放手 提交于 2019-12-07 13:01:10
问题 I am not an experienced MVC3 developer but I'm trying to be. I am familiar with POCO classes and also ViewModels, as the former describes each classes of the database and the latter is used for strong type views in mvc3. My question is not that complicated for the experienced developers but I am a little confused about that. The matter is that, I have a solution containing three projects; The Model class library in which I have wrote my POCO classes. Here is an example: . public class Service

EF Code First implemented interface property

倾然丶 夕夏残阳落幕 提交于 2019-12-07 12:19:23
问题 I have the following model. interface IKeywordedEntity { IEntityCollection<Keyword> Keywords { get; } } class Foo : EntityBase, IKeywordedEntity { public virtual IEntityCollection<Keyword> Keywords { get { ... } } } class Bar : EntityBase, IKeywordedEntity { public virtual IEntityCollection<Keyword> Keywords { get { ... } } } I want to write an extension method that takes care of the keywords automatically for each of these in OnModelCreating . public static void WithKeywords<TEntityType>

ASP.Net MVC 3 EF “Introducing FOREIGN KEY constraint on table may cause cycles or multiple cascade paths”

試著忘記壹切 提交于 2019-12-07 12:03:57
问题 I am creating an ASP.Net MVC 3 application and I am running into a foreign key constraint problem when trying to update my database using migrations. I am using Code-First, and the error I am getting is: Introducing FOREIGN KEY constraint 'FK_CategoryItemValues_CategoryProperties_CategoryPropertyId' on table 'CategoryItemValues' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint.

Self-referencing many-to-many relationship EF code first

不羁的心 提交于 2019-12-07 11:17:17
问题 I work with ASP.NET MVC With Durandal/Breeze templates. Let's say I have the following class: public class Person { public int Id { get; set; } public string Firstname { get; set; } public string Lastname { get; set; } public virtual List<Person> Friends { get; set; } } With the following EF Fluent API: modelBuilder.Entity<Person>() .HasMany(m => m.Friends) .WithMany() .Map(m => m.ToTable("Friends")); The database is generated successfully. The problem is when I perform a que ry with Breeze