locked
Entity Framework query has incorrect column/table names RRS feed

  • Question

  • User-626088549 posted

    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?


    Thanks!

    Monday, November 24, 2014 9:46 AM

Answers

  • User-626088549 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 24, 2014 11:09 AM

All replies

  • User-626088549 posted

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 24, 2014 11:09 AM
  • User-1926401737 posted

    Hi getoutofmylaboratory,

    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.

    Best Regards,

    Sw-ing

    Tuesday, November 25, 2014 1:42 AM