c# - Include only partial entity in EF6 Include -


i have model includes punches can have attachments has properties id, name binarydata.

if do:

var result = context.punchset    .where(p => p.punchtype == punchtype && p.project.id == projectid)    .include(c => c.contractor)    .include(c => c.clearedby)    .include(c => c.createdby)    .include(a => a.attachments) 

the query slow molassis since attachments can both many , large. in case need id , name of attachments. tried:

var result = context.punchset     .where(p => p.punchtype == punchtype && p.project.id == projectid)     .include(c => c.contractor)     .include(c => c.clearedby)     .include(c => c.createdby)     .include(a => a.attachments.select(a2 => new attachment() { id=a2.id, name=a2.name} ); 

but ends error:

the include path expression must refer navigation property defined on type. use dotted paths reference navigation properties , select operator collection navigation properties. parameter name: path

have not idea means , i've been stuck hours. how can include partial entitiy in result? i.e. don't read binary data.

you can try select desired properties in single query , join them in memory.

db.punchset     .include(x => x.contractor)     // ... other includes of complete objects     // select properties partial include     .select(x => new { obj = x, att = x.attachments.select(a => new { a.id, a.name }) })     // end of database query context     .asenumerable()     // join results in memory     .select(x =>     {         x.obj.attachments = x.att.select(a => new attachment() { id = a.id, name = a.name }).tolist();         return x.obj;     }); 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -