Retrieve an object from entityframework without ONE field

Is there a way to retrieve a List but without this column filled?

Not without projection which you want to avoid. If the column is mapped it is natural part of your entity. Entity without this column is not complete – it is different data set = projection.

I’m using here the anonymous type because otherwise you will get a
NotSupportedException: The entity or complex type ‘ProjectName.File’
cannot be constructed in a LINQ to Entities query.

As exception says you cannot project to mapped entity. I mentioned reason above – projection make different data set and EF don’t like “partial entities”.

Error 16 Error 3023: Problem in mapping fragments starting at line
2717:Column Files.Data in table Files must be mapped: It has no
default value and is not nullable.

It is not enough to delete property from designer. You must open EDMX as XML and delete column from SSDL as well which will make your model very fragile (each update from database will put your column back). If you don’t want to map the column you should use database view without the column and map the view instead of the table but you will not be able to insert data.

As a workaround to all your problems use table splitting and separate the problematic binary column to another entity with 1 : 1 relation to your main File entity.

Leave a Comment