我已经为我的Windows应用程序设置了一个ADO实体模型,并且能够从表中获得我需要的数据。然而,当我尝试更新/插入/删除它时,它只是不喜欢我正在使用的代码,但那是因为我不确定我做得是否正确,甚至不确定我做得是否正确。
我的困惑是我通过silverlight和Ria服务学习了WPF,所以我在我的应用程序中所做的是,我已经建立了我的模型,并且我已经创建了域服务。这对于获取数据很有效。下面是我的代码,以及silverlight所需的代码:
Windows:
WebsiteProfileService wps = new WebsiteProfileService();
cbProfile.ItemsSource = wps.GetWebsite_Profile();其中wps是我创建的配置文件服务,cbProfile是一个组合框,现在填充了不同的选项。
同样,silverlight也是这样的:
WebsiteProfileService wps = new WebsiteProfileService();
...
LoadOperation<Website_Profile> loadPro = wps.Load<Website_Profile>(wps.GetWebsite_ProfileQuery());
loadPro.Completed += new loadedeventhander(loadPro_Completed);
void loadPro_Completed(sender, e)
{
cbProfile.Itemsource = wps.Website_Profile;
}现在,有一些简单的查询方法,但我认为这不是一个silverlight问题。
现在,在同样徒劳的情况下,要更新、插入、删除对象,我会在silverlight中执行类似以下操作:
//Create the object
Website_Profile wp = new Website_Profile{
Name = Test,
Value1 = 10,
};
wps.Website_Profile.add(wp); // this adds it to the entity
wps.submitchanges(); //this submits data back to the database无论如何,这就是我所期望的工作方式,但现在我没有提供提交更改()的选项,甚至没有wps.Website_Profile作为选项……
我确实可以访问wps.Submit(),但它不接受0值,并且想要关于changelog的一些东西,这是我还没有遇到的东西。
如果你知道任何可以帮助我的在线信息或教程,请让我知道,我在谷歌上的所有搜索都指向了silverlight,而这并不是我现在需要的。
或者,如果您知道在WPF应用程序中让windows应用程序与数据库进行交互的更好方法,我洗耳恭听,但我可能还有一些后续问题。:)
耽误您时间,实在对不起,
发布于 2011-05-04 22:33:13
Linq to SQL比实体框架更容易使用,而且可能更适合您的第一个应用程序。不要一次学太多东西,给自己增加负担。
发布于 2011-05-04 22:36:53
也许,您可以在这里使用domain driven design和存储库模式?可以在here中找到对存储库模式的非常简单的解释,并且this conversation在这个主题上有许多有用的链接。
https://stackoverflow.com/questions/5885019
复制相似问题