ef-code-first

MigrateDatabaseToLatestVersion not executed

流过昼夜 提交于 2019-12-20 18:18:12
问题 I can't figure out why my latest migration is not getting executed automatically on application startup (or at least on first access of the database context). I used to run update-database manually in development, but I want to test whether it will upgrade automatically on my hosted test environment. In Application_Start(): Database.SetInitializer<FepazoContext>( new MigrateDatabaseToLatestVersion<FepazoContext, FepazoConfiguration>()) In FepazoConfiguration: internal sealed class

Entity Framework 5, switch from code first to database first?

我只是一个虾纸丫 提交于 2019-12-20 14:41:55
问题 I've already created a database using code first. It worked well. Many changes have since been made to the database outside Visual Studio. So many that any attempt at migration generates errors. So my question is, is there a way to switch a solution from code first to database first? 回答1: This should be easy, just create a new, database first model and delete your code first model. Most of your code will compile just fine if you are in the same namespace and take care of naming your context

Entity Framework 5 Code First - How to “start over”?

青春壹個敷衍的年華 提交于 2019-12-20 10:48:29
问题 I've been using EF 5 Code First, successfully, in my app. I have roughly 40 tables. However, I've run into an issue that I can seem to get Migrations to handle correctly. So, what I would like to do is to somehow tell EF to treat the current schema of the database as a new starting point, and start managing it from this point. This way, I can make the necessary schema change manually, and then tell EF to essentially start over from this point. Is there a way I can do this? I presume I'm going

Entity Framework Code First Class with parent and children of same type as it's own class

Deadly 提交于 2019-12-20 10:47:33
问题 I have a class of Content which should be able to have a parentId for inheritance but also I want it to have a list of child content which is nothing to do with this inheritance tree. I basically wanted a link table as ChildContentRelationship with Id's for parentContent and childContent in it and the Content class would have a list of ChildContentRelationship. This has caused a lot of errors. Here's waht I sort of want to do public class Content { public int Id { get; set; } public int?

Entity Framework: The provider did not return a providermanifest instance

泪湿孤枕 提交于 2019-12-20 10:28:11
问题 Entity Framework 6.0.1 my App.config: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <startup> <supportedRuntime version=

EntityFramework.dll vs System.Data.Entity.dll — ambiguity

痞子三分冷 提交于 2019-12-20 09:57:46
问题 I wonder what EntityFramework.dll and System.Data.Entity.dll have in common and what they have different? My project references System.Data.Entity.dll (June CTP) to leverage code first model and everything works fine. Now I wish to use Code First Migrations tool, and it requires EntityFramework.dll that I also have to add to my project. However, when both libraries (EntityFramework.dll and System.Data.Entity.dll) are referenced, I get a lot of compiler errors arguing that some classed are

Multipleactiveresultsets in Entity Framework 4.1 Code First

会有一股神秘感。 提交于 2019-12-20 09:03:21
问题 This is my first EF project so bear with me please. When updating an entity such as Department, you pull it from the context, update its values and call context.SaveChanges. However, if you update Department.Employees, EF does not find that funny. I searched and came up with the option of setting Multipleactiveresultsets=true in the connection string but want to know if: Is this the recommended way? Does this adversely affect performance / what should I look out for? 回答1: Enabling MARS is

Reinstantiating EF classes with one-to-many relationship and compound key of strings

拈花ヽ惹草 提交于 2019-12-20 07:15:00
问题 I have the following EF Code First classes, which appear to be working to a point. I also have Initialization code that seeds these tables with data from elsewhere that is lengthy, and seems (I hope) inconsequential to my question. Or at the least when I seed manually I see the same behavior problem. Note, that these tables use strings as their primary keys, and not ID's. Also note that the SubCategory table has a compound primary key that includes the parent table, Category's primary key,

ASP.Net EF identity column issue, Duplicate entries on single operation

随声附和 提交于 2019-12-20 06:15:03
问题 In APS.NET Entity Framework I am specifying state_id as a Identity column and same as I have set it Auto-Incremented field in MySql Table. But when I perform insert operation it makes one more duplicate entries for the same data with different id. Here it is my code. I has used [DatabaseGenerated(DatabaseGenerationOption.Computed)] property on state id to make it identity. Hey guys I have just check it with break point and I found something very interesting, When 1st time I run this code add(

Proper way to update entity from controller Edit action?

坚强是说给别人听的谎言 提交于 2019-12-20 05:33:13
问题 Controller First I tried this: [HttpPost] public ActionResult Edit(JournalEntry journalentry) { if (ModelState.IsValid) { db.Entry(journalentry).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index", new { id = journalentry.Journal.JournalId }); } return View(journalentry); } Error was thrown in SaveChanges() : Error Message: "Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities