I have a varbinary(max) field in one of my tables but I don't need it every time and I'm looking for a way to fetch it from the database only when necessary. I'm using ADO.NET Entity Framework. How to do that?
views:
710answers:
2
+1
A:
One way would be to project your result set into an anonymous type when you don't need the blob:
from entity in context.Entities
select new
{
Field1 = entity.Field1,
Field2 = entity.Field2
}
In this example, only Field1 and Field2 will be loaded.
This method has the disadvantage that you cannot update the returned instance and do context.SaveChanges. Though I would argue that saving an instance without full knowledge of the instance is borderline unsafe. This method is good when you want a long list of return the instances, but will be querying for a single instance, varbinary field and all, before you actually update.
Craig Stuntz
2009-03-19 17:23:02
Thank you for your assistance. I was looking for something similar to lazy loading of the varbinary field :) but it seems that this isn't possible.
Emil
2009-03-20 11:42:40
+3
A:
The solution was to create a separate table with the varbinary field and make 1-to-1 relationship between the tables
Emil
2009-03-20 11:44:02