JMarsch
JMarsch

Reputation: 21753

Entity Framework 4.1 and BLOBs

I'm trying to work out what the best way to work with BLOBs and entity framework.

I am working with EF 4.1, and using POCO's/DbContext

So here's and example table:

MyTable
Key int
SomeFields ...
ABlob  (ok, it's actually a Text, but whatever)

Now, sometimes when I select from MyTable, I want to include the BLOB field, but a lot of the time, I don't.

Also, sometimes, when I update MyTable, I want to update the BLOB. but a lot of the time, I don't.

I could use anonymous types for the select operation, but I cannot seem to find a way to make this work at all for updates (I can't have 2 different classes in the same context mapped to the same table, if I try to use inheritance, I get a runtime error because EF is expecting a discriminator column).

Surely using EF doesn't mean that I always have to query all of my BLOBs. What am I missing here?

Upvotes: 4

Views: 1641

Answers (2)

Giorgio Minardi
Giorgio Minardi

Reputation: 2775

You can try by calling a stored procedure or execute the SQL statement from your code :

var result= context.Database.SqlQuery<string>("SELECT yourfield FROM yourtable").ToList();

Here some documentation

Upvotes: 1

amit_g
amit_g

Reputation: 31250

This could be done using Table Splitting. EF 4.1 and EF 4.

Upvotes: 4

Related Questions