Linq to SQL EntitySet Binding the MVVM way
Posted
by Savvas Sopiadis
on Stack Overflow
See other posts from Stack Overflow
or by Savvas Sopiadis
Published on 2009-12-17T23:02:38Z
Indexed on
2010/05/13
22:04 UTC
Read the original article
Hit count: 1109
Hi everybody!
In a WPF application i'm using LINQ to SQL classes (created by SQL Metal, thus implementing POCOs).
Let's assume i have a table User and a Table Pictures. These pictures are actually created from one picture, the difference between them may be the size, coloring,...
So every user may has more than one Pictures, so the association is 1:N (User:Pictures).
My problems:
a) how do i bind, in a MVVM manner, a picture control to one picture (i will take one specific picture) in the EntitySet, to show it up?
b) everytime a user changes her picture the whole EntitySet should be thrown away and the newly created Picture(s) should be a added. Is this the correct way?
e.g.
//create the 1st piture object
UserPicture1 = new UserPicture();
UserPicture1.Description = "... some description.. ";
USerPicture1.Image = imgBytes; //array of bytes
//create the 2nd piture object
UserPicture2 = new UserPicture();
UserPicture2.Description = "... another description.. ";
UserPicture2.Image = DoSomethingWithPreviousImg(imgBytes); //array of bytes
//Assuming that the entityset is called Pictures
//add these pictures to the corresponding user
User.Pictures.Add(UserPicture1);
User.Pictures.Add(UserPicture2);
//save changes
datacontext.Save()
Thanks in advance
© Stack Overflow or respective owner