【问题标题】:CRUD Operations in a C# WFP Windows application that interacts with ADO Entity Model与 ADO 实体模型交互的 C# WFP Windows 应用程序中的 CRUD 操作
【发布时间】:2011-05-04 22:36:52
【问题描述】:

我已经为我的 Windows 应用程序设置了一个 ADO 实体模型,并且能够从我需要的表中获取数据。但是,当我尝试更新/插入/删除时,它只是不喜欢我正在使用的代码,但那是我不确定我是否做得对,甚至是否接近正确。

我的困惑是我学习了使用 silverlight 和 Ria 服务的 WPF,所以我在应用程序中所做的是我已经设置了我的模型,并且我已经创建了域服务。这适用于获取数据。这是我的代码,以及 Silverlight 中需要的代码:

窗户:

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 中执行以下操作:

//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

无论如何,这就是我期望它起作用的方式,但现在我没有看到 submitchanges() 的选项,甚至没有 wps.Website_Profile 作为选项...

我确实可以访问 wps.Submit(),但它不需要 0 值,并且想要一些关于变更日志的内容,而这是我还没有遇到的。

如果您知道任何可以帮助我的信息或在线教程,请告诉我,我所有的 google 搜索都将我指向 silverlight,这不是我现在需要的。

或者,如果您知道让 Windows 应用程序与 WPF 应用程序中的数据库交互的更好方法,我会全力以赴,但我可能还有一些后续问题。 :)

感谢您的宝贵时间,

【问题讨论】:

    标签: c# wpf entity-framework-4 crud


    【解决方案1】:

    Linq to SQL 比实体框架更容易使用,并且可能更适合您的第一个应用程序。不要一次学习太多东西给自己带来负担。

    【讨论】:

      【解决方案2】:

      也许,您可以在此处将domain driven design 与存储库模式一起使用?可以在here 找到非常简单的存储库模式解释,this conversation 有许多关于该主题的有用链接。

      【讨论】:

        猜你喜欢
        • 2014-12-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-30
        • 2010-10-29
        • 2013-04-15
        • 2012-01-04
        相关资源
        最近更新 更多