New Posts New Posts RSS Feed: Deleting a blob without loading the record.
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Deleting a blob without loading the record.

 Post Reply Post Reply
Author
BringerOD View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 27-Aug-2010
Location: USA
Posts: 35
Post Options Post Options   Quote BringerOD Quote  Post ReplyReply Direct Link To This Post Topic: Deleting a blob without loading the record.
    Posted: 11-Sep-2010 at 2:57pm

Is there any way to delete a row in a table without querying it first?

I need to delete a file with a large amount of data with loading it.
 
I saw this code below on EF and it does not seem to work with DevForce.
 
I guess I could attach a stored procedure.
 
 
---------------------------------------------------------------------

var file = new File();

file.FileId = CurrentEntity.FileId.Value;

file.EntityKey = new EntityKey("PrimeEntities.Files", "FileId", CurrentEntity.FileId.Value.ToString());

PrimeEntities.Attach(file);

PrimeEntities.DeleteObject(file);

PrimeEntities.SaveChanges();

Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 12-Sep-2010 at 11:19am
I think you can define an entity that doesn't load all the properties.

Say you have a table called File with columns FileId and Data, you can have your entity only load the FileId column, and then you are not loading the blob data.
Back to Top
BringerOD View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 27-Aug-2010
Location: USA
Posts: 35
Post Options Post Options   Quote BringerOD Quote  Post ReplyReply Direct Link To This Post Posted: 12-Sep-2010 at 11:26am

How do you only load the FileId column?

 
Bryan
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Posted: 12-Sep-2010 at 11:36am
I'm not sure if there is a better way, but this is one approach:

http://blogs.msdn.com/b/adonet/archive/2008/12/05/table-splitting-mapping-multiple-entity-types-to-the-same-table.aspx

You are essentially splitting your table into two entity types. One with the image, one without. If you don't want the image you simply query the one without the image.
Back to Top
BringerOD View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 27-Aug-2010
Location: USA
Posts: 35
Post Options Post Options   Quote BringerOD Quote  Post ReplyReply Direct Link To This Post Posted: 12-Sep-2010 at 11:54am
Thanks!
 
I have done the table splitting before.  I guess I just forgot about it, since I already made a seperate table for the files, I figured I would not have to split the file table.  Seemed redundant.  It is a solution though. 
 
I think I will just use the a stored procedure.
 
Thanks for your help.
 
Bryan
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down