序列化Linq实体 [英] Serialize Linq entities

查看:67
本文介绍了序列化Linq实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的问题如下.我正在使用Linq将数据从数据库中检索到sql,然后将该数据绑定到Windows窗体上的控件.在我的应用程序的下一部分中,我想获取对数据所做的更改,然后序列化为XML或二进制.然后,当我第二次加载应用程序时,我想反序列化该数据并提交在上一个会话"中所做的更改.

我正在尝试将我的Linq序列化为sql实体,但这没有用.也许你们可以在我尝试了很多事情并在互联网上寻找可能的解决方案并找不到任何东西时,向我指向文章或教程或提供一些指导.

非常感谢您的帮助.

Hi,

My problem is the following. I am retrieving data from the database using Linq to sql and then binding that data to controls on my windows forms. The next part of my application I want to get the changes made to the data and serialize then to either XML or binary. Then when i load the application the second time i want to deserialize that data and commit the changes that where made in the previous "session".

I am trying to serialize my Linq to sql entities but it''s no use. Maybe you guys can point me to an article or tutorial or provide some guidance as i tried many things and looking trough the internet for possible solutions and cant find anything.

Your help is greatly appreciated guys.

Thx a lot.

推荐答案

如果使用Entity Framework,则所有实体都可以序列化.因此,请尝试序列化和反序列化过程:
If you used Entity Framework, then all entity become serializable. So try serialization and De-serialization process:
SomeModel model = ...
var serializer = new XmlSerializer(typeof(SomeModel));
using (var writer = XmlWriter.Create("foo.xml"))
{
    serializer.Serialize(writer, model);
}
and to deserialize back a XML to an existing model:

var serializer = new XmlSerializer(typeof(SomeModel));
using (var reader = XmlReader.Create("foo.xml"))
{
    var model = (SomeModel)serializer.Deserialize(reader);
}


是的,这会跟踪已完成的插入和更新吗?因为就我而言,我想临时保存数据,然后在以后提交更改.
Yes will this keep track of the inserts and updates that have been done? Because in my i case i want to temporary save the data and then commit the changes at a later time.


这篇关于序列化Linq实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆