L
Lagrange
Hi,
Suppose that I have a table named 'Image' with primary key 'ID' (of
int type) and binary data column named 'Data' (of Image type) on MS
SQL database.
I am using Linq to SQL.
Then if I want to delete items that satisfy some condition I write:
DefaultDataContext dataContext = new DefaultDataContext ();
var itemsToDelete = dataContext.Images.Where(item => item.ID > 10)
dataContext.Images.DeleteAllOnSubmit(itemsToDelete);
If I understand this correctly, whenever an implicitly typed variable
(var) is casted to IEnumerable the query is executed (and depending on
query type data retrieved from DB).
As DeleteAllOnSubmit accepts a IEnumerable<Images> parameter, my
itemsToDelete linq query is, indeed, casted to IEnumerable, hence, the
query is executed and all the Images that satisfy the condition ID >
10 are fetched instantiated in my app's memory prior.
For what? Only to tell the DB ID's of Images to delete in the
following step?
Did I catch the point?
Now suppose, that my records are really big peaces of data. Why should
I have my application filling the memory with such a volume of
information when all it needs to do is, in fact, to tell MS SQL the
condition for items to be deleted?
I know that I can execute direct SQL statement via data-context
object. But tell me, does some more elegant, more "linquish" way
exist?
Thanks in advance.
Peter.
Suppose that I have a table named 'Image' with primary key 'ID' (of
int type) and binary data column named 'Data' (of Image type) on MS
SQL database.
I am using Linq to SQL.
Then if I want to delete items that satisfy some condition I write:
DefaultDataContext dataContext = new DefaultDataContext ();
var itemsToDelete = dataContext.Images.Where(item => item.ID > 10)
dataContext.Images.DeleteAllOnSubmit(itemsToDelete);
If I understand this correctly, whenever an implicitly typed variable
(var) is casted to IEnumerable the query is executed (and depending on
query type data retrieved from DB).
As DeleteAllOnSubmit accepts a IEnumerable<Images> parameter, my
itemsToDelete linq query is, indeed, casted to IEnumerable, hence, the
query is executed and all the Images that satisfy the condition ID >
10 are fetched instantiated in my app's memory prior.
For what? Only to tell the DB ID's of Images to delete in the
following step?
Did I catch the point?
Now suppose, that my records are really big peaces of data. Why should
I have my application filling the memory with such a volume of
information when all it needs to do is, in fact, to tell MS SQL the
condition for items to be deleted?
I know that I can execute direct SQL statement via data-context
object. But tell me, does some more elegant, more "linquish" way
exist?
Thanks in advance.
Peter.