Retrieve an object from entityframework without ONE field

后端 未结 8 2330
[愿得一人]
[愿得一人] 2020-11-30 02:54

I\'m using entity framework to connect with the database. I\'ve one little problem:

I\'ve one table which have one varbinary(MAX) column(with filestream).

I\

8条回答
  •  暖寄归人
    2020-11-30 03:43

    I'd do something like this:

    var result = from thing in dbContext.Things
                 select new Thing {
                     PropertyA = thing.PropertyA,
                     Another = thing.Another
                     // and so on, skipping the VarBinary(MAX) property
                 };
    

    Where Thing is your entity that EF knows how to materialize. The resulting SQL statement shouldn't include the large column in its result set, since it's not needed in the query.

    EDIT: From your edits, you get the error NotSupportedException: The entity or complex type 'ProjectName.File' cannot be constructed in a LINQ to Entities query. because you haven't mapped that class as an entity. You can't include objects in LINQ to Entities queries that EF doesn't know about and expect it to generate appropriate SQL statements.

    You can map another type that excludes the VarBinary(MAX) column in its definition or use the code above.

提交回复
热议问题