Last post Nov 25, 2014 01:42 AM by sw-ing
Nov 24, 2014 09:46 AM|getoutofmylaboratory|LINK
I have a database-first project using entity framework. I built custom models as opposed to using the code generator. Things seem to be ok with that, however, when I run a query, the table and column names are off. For example, I have a User model with a
property called 'Name'. Name consists of FirstName, MiddleName, and LastName. I modified the edmx to convert those fields into a complex type called Name also. When the query runs, I see this over profiler:
[Extent1].[Name_FirstName] AS [Name_FirstName],
[Extent1].[Name_MiddleName] AS [Name_MiddleName],
[Extent1].[Name_LastName] AS [Name_LastName],
Obviously, this is wrong as there are no columns in the table named [Name_FirstName], it's simply [FirstName], and this is how the edmx shows it as being mapped to.
So the next thing I noticed, is that somewhere it is thinking that my table names are pluralized, when in fact they are singular. So all the queries are selecting from tables like [dbo].[Users] when it should be [dbo].[User]. I remember there being a setting
in OnModelCreating (for Code first), but don't recall this for Database First.
I'm using Entity Framework 6.
How can I fix this?
Nov 24, 2014 11:09 AM|getoutofmylaboratory|LINK
Well it seems that the possible cause of this was that my application was trying to use code first when I was wanting it to use database first. I'll start a new thread with the problem I'm facing now.
Nov 25, 2014 01:42 AM|sw-ing|LINK
This video and step-by-step walkthrough provide an introduction to Code First development targeting a new database.
This video and step-by-step walkthrough provide an introduction to Code First development targeting an existing database.
Hope it will be helpful to you.