ef-code-first

Second attempt to generate script sql script did not work

感情迁移 提交于 2019-12-11 10:46:56
问题 I am developing an application in ASP.NET MVC 5 and Entity Framework with a code-first approach. Firstly, I had one class in my data context file and everything worked. enable-migrations , add-migration and update-database were working fine but second time, I added more classes and tried to execute these statements: enable-migrations -ContextTypeName IdentityDb -MigrationsDirectory DAL\IdentityMigrations enable-migrations -ContextTypeName SMSContext -MigrationsDirectory DAL\SMSMigrations add

Entity Framework (.NET) Round-Trip Modelling with Model First?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 09:53:08
问题 I am currently working on a project where I want to use the Entity Framework for the first time. I read much information in the books of Lerman/Miller, in MSDN, the ADO.NET blog and here on stackoverflow about the most recent developments regarding the DbContext API and the Code First Migrations capabilities available since EF 4.3. Since especially the latter are really great, I wondered whether in the meantime it is possible to do the same working "Model First" centered? Is it possible to do

How to cleanly generate POCO classes from existing database using Entity Framework 4.3 Code First approach?

♀尐吖头ヾ 提交于 2019-12-11 09:37:33
问题 I'm following the EF Code-First approach in a project that works against an existing database, to which I'm adding tables as needed. This database has a number of tables for which I need to generate POCO classes for, and so I was wondering if there was a straight-forward, clean approach, to generating simple POCO classes from the database ... from which I can continue to work with using the general Code-First paradigm? 回答1: You can use the Entity Framework Power Tools for that. 回答2: If you

Specific Entity Framework Code First Many to 2 Model Mapping

狂风中的少年 提交于 2019-12-11 09:24:43
问题 I'm a bit of a loss here. Basically I have these two Models: public class Player { public int PlayerId { get; set; } public string Name { get; set; } public virtual ICollection<Game> Games { get; set; } } public class Game { public int GameId { get; set; } public virtual Player PlayerBlack { get; set; } public virtual Player PlayerWhite { get; set; } } Now the Database Schema, EF Code First creates for me, is not correct because the Game table gets 3 Foreign Keys (Playerblack, PlayerWhite and

Entity Framework 5 Cannot use Ignore method on the property

我与影子孤独终老i 提交于 2019-12-11 08:55:08
问题 I have almost exhausted all of the workarounds for this bug: http://entityframework.codeplex.com/workitem/481 Please can someone point me in the right direction. I have done the following: Step 1: Remove the NotMapped attribute from the properties in all entities and base classes. There are no NotMapped attributes left in my solution at all. Step 2: Use the ignore method in the OnModelCreating method for all properties on all entities (Seriously this took me a couple days with the sheer

EF Codefirst Convert Base Class to Derived Class

别等时光非礼了梦想. 提交于 2019-12-11 08:47:19
问题 Supposing the following entities : public class Kisi { [Key] public int KisiID { get; set; } public string Ad { get; set; } public string Soyad { get; set; } public virtual ICollection<Grup> Gruplar { get; set; } public virtual ICollection<Kampanya> Kampanyalar { get; set; } } public class Musteri : Kisi { public int? Yas { get; set; } public string Meslek { get; set; } } These two classes storing one table(TPH) in SQL SERVER. I saved a Kisi and this could be in relation to other tables. How

Entity Framework: Split table into multiple tables

淺唱寂寞╮ 提交于 2019-12-11 08:46:29
问题 I have the following table [PaymentComponent] created using following EF code first approach (TPH inheritance). It works fine. I need to change the database design – need to store GiftCouponPayments in GiftCouponPayment table and ClubCardPayments in ClubCardPayment table. What change need to be done in C# code to get the required database structure? CODE public abstract class PaymentComponent { public int PaymentComponentID { get; set; } public int MyValue { get; set; } public string MyType {

error 0019: Each property name in a type must be unique on ID field

℡╲_俬逩灬. 提交于 2019-12-11 08:44:57
问题 ANSWERED! (will be posting it shortly. I seriously think it's a bug in EF.) I have the following set of (code-first) classes which will be the future of the application as we are replacing the old (gen'd from db). The dbcontext, two mappings/configurations, two POCOs, and a base class. In addition to this in another project entirely is an edmx generated from the database. Up until now, there have not been any issues with the two conflicting. There are several other unrelated sets in the

How to prevent Code First from enabling foreign key constraint on a relationship?

耗尽温柔 提交于 2019-12-11 08:37:31
问题 I have two entities, User and Feedback, and there is one-to-many relationship between those with help of the username field. Feedback --> User -------- -------- username username However, sometimes feedback may code from an unregistered user, and Username field on Feedback will be Null. In that case, the addition of feedback will fail due to the foreign key constraint. How can I disable the enforcement of a foreign key constraint on a relationship declaratively or by means of the Fluent API?

EF5 Code First: Force many to many recursive relationship

浪尽此生 提交于 2019-12-11 08:29:58
问题 I have a simple Entry class model public class Entry { public int Id { get; set; } public DateTime Modified { get; set; } public DateTime Created { get; set; } // Related entries public virtual ICollection<Entry> RelatedEntries { get; set; } // The nodes this entry contains public virtual ICollection<Node> Nodes { get; set; } // The category this entry is located in public virtual Category Category { get; set; } } I want my entry to be able to have a list of related entries, the problem is it