Linq to SQL EntitySet 绑定 MVVM 方式
在 WPF 应用程序中,我使用 LINQ to SQL 类(由 SQL Metal 创建,从而实现 POCO)。
假设我有一个用户表和图片表。这些图片实际上是由一张图片创建的,它们之间的差异可能是大小、颜色……
所以每个用户可能有不止一张图片,所以关联是1:N(用户:图片)。
我的问题:
a)我如何以MVVM方式将图片控件绑定到EntitySet中的一张图片(我将拍摄一张特定图片),以显示它向上?
b) 每次用户更改其图片时,整个 EntitySet 都应被丢弃,并应添加新创建的图片。这是正确的方法吗?
例如,
//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()
提前致谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有两个选择给你(但还有更多)。
如果您需要更多详细信息,请发表评论。
干杯,安瓦卡
I have two options for you (but there are many more).
Please comment if you need more details.
Cheers, Anvaka