Print Page | Close Window

Getting entity back but skipping some fields

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3109
Printed Date: 13-Oct-2025 at 3:26am


Topic: Getting entity back but skipping some fields
Posted By: katit
Subject: Getting entity back but skipping some fields
Date Posted: 23-Nov-2011 at 7:00pm
I have some entities which contain binary data. I'd like to query this data but skip that binary field so I can download it later on demand. Is that possible somehow?
 
var query =
                from mi in this.entityManager.SYSMailItems
                    .Include(SYSMailItem.PathFor(x => x.MEMUser))
                    .Include("SYSMailRecipients.MEMUser")
                    .Include(SYSMailItem.PathFor(x => x.SYSMailAttachments))
                orderby mi.MailItemKey descending
                select mi;
 
I'm talking about SYSMailAttachments.
I understand I can brake this query into 2 and make projection into custom/anon object but I really like to get all this info in one shot and then get binary data separately. Any magic I can use within DevForce?



Replies:
Posted By: DenisK
Date Posted: 23-Nov-2011 at 7:51pm
Hmm, the only way I can think of is to separate that binary data field into another entity. So you will have a 1:1 or 0,1:1 relationship with the binary data entity.

This is probably be better as well in the long run as downloading large chunks of binary data can consume large memory.


Posted By: katit
Date Posted: 23-Nov-2011 at 7:57pm
Right. I was also thinking about moving it into separate table in SQL Server.
 
Or do you mean I can separate this into entity with Entity designer?


Posted By: DenisK
Date Posted: 28-Nov-2011 at 12:56pm
You actually need to create a separate table and entity for this. The main entity will have this binary data entity as a navigation entity which, when you do your queries, you can choose to not include this entity, thus reducing your payload.


Posted By: DenisK
Date Posted: 28-Nov-2011 at 2:22pm
Just found out that you don't have to create a separate table for this. You can map a table to multiple entities. This concept is called Table Splitting in EF.

http://www.deveducate.com/blog/post/2010/12/14/Entity-Framework-Modeling-Table-Splitting.aspx - http://www.deveducate.com/blog/post/2010/12/14/Entity-Framework-Modeling-Table-Splitting.aspx

There's also the opposite concept called Entity Splitting where you can map an entity to multiple tables. 

http://msdn.microsoft.com/en-us/library/cc716698.aspx - http://msdn.microsoft.com/en-us/library/cc716698.aspx




Posted By: katit
Date Posted: 28-Nov-2011 at 2:26pm
I already split actual table, it will be better in a long run I think. Splitting entity will be problematic if I want to regenerate model from scratch. Right now I can do it easily.



Print Page | Close Window