Entity Framework Invalid column name when adding property that is not in db table

user5154099

I had decided that there are just too many things that need to be different on the View Presentation Layer compared to what is actually in the database table.

I have a class of properties in C# that represents the model of my database HOWEVER I was reading about ViewModels and I can see how they can do the nice things of not displaying containing an unnecessary amount of data that you do not wish to display on your view, and it can also be an important aggregrate of combining multiple models in which you have much more available to you for trickling down to the View.

I simply tried to add a class with a property

  public class ExtendedFile
  {
     public string FileSize { get; set; }
  }

Then I figured I could simple add this as another property to my other model class , so I added it

public ExtendedFile ExtendedFile { get; set; }

Then it seems that I can in my controller simply hydrate this

 file.ExtendedFile.FileSize = ConvertFileSize(file.size);

So then my View now has

<td>@item.ExtendedFile.FileSize</td>

Well that did not work out .. A controller method had code in it in which a linq query that joins 2 tables freaked out. The error message is:

Invalid column name 'ExtendedFile_FileSize'.

The code that causes the error is:

var query = (
    from qtips in dbProd.tblTips 
    where qtips.id == 30 
    join files in dbProd.tblFiles on qtips.id.ToString() 
    equals files.@group select new { qtips, files }).ToList();
user5154099

Thanks to Stephen while I realize that I "can" do use this other model, I'm just going really against the proper patterns in which what a true ViewModel is for

Thus I already had this working 40 minutes ago by simply adding the [NotMapped]

[NotMapped]
public ExtendedFile ExtendedFile { get; set; }

It exposes a bigger issue of the fact that I was not understanding the ViewModel.

So while that "works" I am going to instead have a ViewModel with

  1. The properties I want to display from the tblFiles class
  2. The properties from this this ExtendedFile class such as

    public class ExtendedFile
    {
        public string FileSize { get; set; }
        //more properties 
    }
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Entity framework : Invalid column name

From Dev

Entity Framework DB First not adding table

From Dev

Entity Framework 4: Invalid Column Name

From Dev

Entity Framework 7 : Generating Invalid Column Name

From Dev

Entity Framework 4: Invalid Column Name

From Dev

Invalid Column Name using Entity Framework

From Dev

C# Entity Framework - Invalid column name

From Dev

entity framework Invalid column name Id (two foreign keys from the same primary table)

From Dev

Entity Framework appending '1' to property name when it matches entity name

From Dev

Entity Framework Invalid Column

From Dev

SqlException 'invalid column name' for composite key tables with Entity Framework

From Dev

Entity Framework: "Invalid column name" error with many to many mapping

From Dev

Entity Framework tries to create user when adding other object to db

From Dev

Entity Framework v6.13 - Adding new column to table

From Dev

Entity Framework code first, set column name on a Boolean property

From Dev

When I do a group by with Entity Framework whats the name property of the list?

From Dev

"Invalid Object Name" error during db.SaveChanges() (Entity Framework/MVC)

From Dev

Entity Framework - DbUpdateException when adding entity

From Dev

Dynamically adding a property to an entity framework object

From Dev

Adding a primary key for Entity Framework to an existing column in a View based on a table where every column is Allow Null

From Dev

Entity Framework suggest invalid field name

From Dev

Entity Framework SqlException: Invalid object name

From Dev

Entity Framework throws Invalid object name

From Dev

ASP.NET MVC /Entity Framework Error - Invalid column name 'Environment_Id'

From Dev

Entity Framework Code First - Invalid column ID

From Dev

The required property {0} does not exist on the type {1}. Entity framework (model first) when adding FK

From Dev

How to prevent Entity Framework from adding ISNULL checks when joining on a nullable property with LINQ

From Dev

EntityCommandExecutionException: Invalid column name 'Entity_Id'

From Dev

Entity framework - 'update from database' not adding table

Related Related

  1. 1

    Entity framework : Invalid column name

  2. 2

    Entity Framework DB First not adding table

  3. 3

    Entity Framework 4: Invalid Column Name

  4. 4

    Entity Framework 7 : Generating Invalid Column Name

  5. 5

    Entity Framework 4: Invalid Column Name

  6. 6

    Invalid Column Name using Entity Framework

  7. 7

    C# Entity Framework - Invalid column name

  8. 8

    entity framework Invalid column name Id (two foreign keys from the same primary table)

  9. 9

    Entity Framework appending '1' to property name when it matches entity name

  10. 10

    Entity Framework Invalid Column

  11. 11

    SqlException 'invalid column name' for composite key tables with Entity Framework

  12. 12

    Entity Framework: "Invalid column name" error with many to many mapping

  13. 13

    Entity Framework tries to create user when adding other object to db

  14. 14

    Entity Framework v6.13 - Adding new column to table

  15. 15

    Entity Framework code first, set column name on a Boolean property

  16. 16

    When I do a group by with Entity Framework whats the name property of the list?

  17. 17

    "Invalid Object Name" error during db.SaveChanges() (Entity Framework/MVC)

  18. 18

    Entity Framework - DbUpdateException when adding entity

  19. 19

    Dynamically adding a property to an entity framework object

  20. 20

    Adding a primary key for Entity Framework to an existing column in a View based on a table where every column is Allow Null

  21. 21

    Entity Framework suggest invalid field name

  22. 22

    Entity Framework SqlException: Invalid object name

  23. 23

    Entity Framework throws Invalid object name

  24. 24

    ASP.NET MVC /Entity Framework Error - Invalid column name 'Environment_Id'

  25. 25

    Entity Framework Code First - Invalid column ID

  26. 26

    The required property {0} does not exist on the type {1}. Entity framework (model first) when adding FK

  27. 27

    How to prevent Entity Framework from adding ISNULL checks when joining on a nullable property with LINQ

  28. 28

    EntityCommandExecutionException: Invalid column name 'Entity_Id'

  29. 29

    Entity framework - 'update from database' not adding table

HotTag

Archive