none
A member of the type, 'ColumnName', does not have a corresponding column in the data reader with the same name RRS feed

  • Question

  • Hello all, i have a problem. Error is pretty clear but i don't know how to fix it

    I use database first approach don't know why but when create Entities, EF put "C" in front of my column. My column name is 216 but in EF is C216 and when i want to get any result from this column i get that error. When i check mapping everything looks fine 216 = C216.

    My question is why EF put random char in front of my column name and how i can fix that

    Wednesday, July 18, 2018 8:07 AM

Answers

  • Hi SeaInTheSky,

    >>My question is why EF put random char in front of my column name and how i can fix that

    Because 216 is a invalid token for C# variable, class, property, etc, so entity framework convert it and add a C in front of it. but entity framework map the property C216 to database field 216. the following code works well. 

    using (var db = new BloggingEntities())
    {
        var aaa = new A_Table() { S_Number = 5, Amount = 10, C216 = "Test" };
        db.A_Table.Add(aaa);
        db.SaveChanges();
    }

    #Table

    Best regards,

    Zhanglong 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by SeaInTheSky Wednesday, July 25, 2018 7:11 AM
    Thursday, July 19, 2018 1:47 AM
    Moderator

All replies

  • Why do you have a column name of 216? It is not a normal column naming convention. I can see EF doing something with the name for the property when creating the virtual model object so that it's valid to EF and C# or VB. 
    Wednesday, July 18, 2018 11:12 AM
  • Can't answer you why column name is 216. As i said its database first (i didn't create this db). I am using c#

    Wednesday, July 18, 2018 12:18 PM
  • Can't answer you why column name is 216. As i said its database first (i didn't create this db). I am using c#

    https://msdn.microsoft.com/en-us/library/ms229043(v=vs.100).aspx

    EF in making the class for the virtual object is following a naming convention. I suggest that the column name on the database table schema follow some kind of naming convention so that EF in generating the virtual object model classes doesn't step in and do the naming that has lead to a mapping problem, becuase the database table columnname is unorthodox. 

    Wednesday, July 18, 2018 12:34 PM
  • Hi SeaInTheSky,

    >>My question is why EF put random char in front of my column name and how i can fix that

    Because 216 is a invalid token for C# variable, class, property, etc, so entity framework convert it and add a C in front of it. but entity framework map the property C216 to database field 216. the following code works well. 

    using (var db = new BloggingEntities())
    {
        var aaa = new A_Table() { S_Number = 5, Amount = 10, C216 = "Test" };
        db.A_Table.Add(aaa);
        db.SaveChanges();
    }

    #Table

    Best regards,

    Zhanglong 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by SeaInTheSky Wednesday, July 25, 2018 7:11 AM
    Thursday, July 19, 2018 1:47 AM
    Moderator