N
news.microsoft.com
I have a desktop aplication which use an embeded database engine (embeded in
the application that is) to store its data.
And I used LINQ 2 SQL as an ORMapper to synchronize the database with my
object representation in memory.
What I want to do is load most object at the start, do in memory work, and
occasionaly load additional big data or save the changes.
I have a problem with the DataContext.GetTable<T>() mehod. It seems
everytime I do a foreach on its retur it will query the database, is that
true?
So in my particular case I'm better off working with an List<T> which I will
initialize from the GetTable<T> result?
Just in case I wrote such a list (Code attached) and I wonder if I did it
the proper way, if anyone can take a look?
Also I have a table like that
Data
--------
ID int
summary nvarchar(256)
content image
which I loaded in
[Table("Data")]
class Data
{
[Column(...)]
public int ID {get; set; }
[Column(...)]
public sring Sumary { get; set; }
[Column(...)]
public byte[] Content { get; set; }
}
Now Content is potentially big and I want to use lazy loading, i.e. I DON'T
want to load the 'byte[] Content' with the rest of the data (I guess it's
easy, just remove the ColumnAttribute), but I DO want to save the Content,
if it's not null (i.e. if it has been explicitely loaded/set/modified) when
SubmitChanges() is called on the Context.
Any tip on how to do that?
Moreover, if I only change the content (which will have no ColumnAttribute)
how do I mark my entity as dirty in the context? (i.e. I would need an
'UpdateOnSubmit()' method in the table, but it doesn't exists..)
the application that is) to store its data.
And I used LINQ 2 SQL as an ORMapper to synchronize the database with my
object representation in memory.
What I want to do is load most object at the start, do in memory work, and
occasionaly load additional big data or save the changes.
I have a problem with the DataContext.GetTable<T>() mehod. It seems
everytime I do a foreach on its retur it will query the database, is that
true?
So in my particular case I'm better off working with an List<T> which I will
initialize from the GetTable<T> result?
Just in case I wrote such a list (Code attached) and I wonder if I did it
the proper way, if anyone can take a look?
Also I have a table like that
Data
--------
ID int
summary nvarchar(256)
content image
which I loaded in
[Table("Data")]
class Data
{
[Column(...)]
public int ID {get; set; }
[Column(...)]
public sring Sumary { get; set; }
[Column(...)]
public byte[] Content { get; set; }
}
Now Content is potentially big and I want to use lazy loading, i.e. I DON'T
want to load the 'byte[] Content' with the rest of the data (I guess it's
easy, just remove the ColumnAttribute), but I DO want to save the Content,
if it's not null (i.e. if it has been explicitely loaded/set/modified) when
SubmitChanges() is called on the Context.
Any tip on how to do that?
Moreover, if I only change the content (which will have no ColumnAttribute)
how do I mark my entity as dirty in the context? (i.e. I would need an
'UpdateOnSubmit()' method in the table, but it doesn't exists..)