MVC 4 and EF6 database first: issue with mapping

asp.net-mvc-4 c# ef-database-first entity-framework entity-framework-6

Accepted Answer

You've encountered EF's conventions, which are both great and occasionally frustrating. It's great when you know the conventions since they make life easier, but it may be annoying when you feel like the framework is doing things without your explicit consent.

First, more details about EF6 conventions are available here: http://msdn.microsoft.com/en-gb/data/jj679962.aspx

Regarding your first issue, to the best of my knowledge, Entity Framework uses the name of the entity as the name of the table it will generate in your database. You've seen that you can regulate this via the "Table" attribute, but you can also control its tendency to want to pluralize your entity names when constructing tables by using convention removal within your DbContext.

modelBuilder.Conventions.Remove<PluralizingTableNameConvention>()

Regarding your second point, I find it difficult to see why you would need to have a "Key" attribute connected to your "RequestId" field. The standard is that EF will automatically include a field as a primary key if the field name includes the case-insensitive ID suffix, and it will automatically establish a field as an auto-seed identification column if the field's type is either an Int or a Guid.

0
1/20/2014 1:04:43 PM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow