ORM与WCF [英] ORM with WCF

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

问题描述

我有一个ORM设计的数据库设置。我已经在datacontext类上将Serialization Mode转换为Unidirectional(通过设计时属性)。我还需要关闭延迟加载,如下所述: http://msdn.microsoft.com /en-us/library/bb546184.aspx


但是,我无法知道如何做到这一点。我需要在设计时通过属性设置它,因为我的ORM模型将使用WCF在中间层。


如何关闭延迟加载?是0I想要使用中间层WCF应用程序(与我已经通过ORM设置的LINQ TO SQL类一起使用)。这将传回数据&介绍与介绍之间数据库层。


我只是对如何设置它感到困惑:(


我试过看过具体的文章,但是我找不到的文章实际上是这样的。这是一个基本的场景,我很惊讶我无法在任何地方找到它。


我已经设置了ORM (除了延迟加载被关闭)。我需要创建WCF服务并将其与ORM项目集成。我需要在WCF服务中设置方法来更新数据库中的数据,但我不确定如何使用ORM LINQ TO SQL类完成此操作。我知道如何在没有ORM的情况下使用它并直接通过ado.net访问db,但我想尝试将ORM LINQ TO SQL类与WCF服务一起使用。 / p>

我怎样才能做到这一点。即使是一些高级别的要点也会受到赞赏。


谢谢。
------- -------------------------------------------------- -----------------------
Bill Yeager


Bill Yeager

解决方案

datacontext上有一个属性,您可以在其中设置:dc.DeferredLoading = false;

我通常会覆盖部分类中的datacontext构造函数,并设置诸如延迟加载之类的东西,还有审计,日志记录等 - 这样我就可以从代码控制我是否需要它。 (有时我确实希望延迟加载WCF服务内部的东西,即对象不会通过电线传播......)

例如:

 public SomeDataContext(string connectString,bool enableProfiling,bool disconnect,Guid userID)
:this(connectString)
{
_currentUserID = userID;

if(disconnect == true)
{
this.DeferredLoadingEnabled = false;
}

if(enableProfiling == true)
{
string profilerOutput = Settings.ProfilerOutput;
_profiler = this.BeginProfiling(profilerOutput,new PageReadFilter(10000),ExecutionPlanMode.Estimated,true);
_profiler.LogError + = new EventHandler(L2SProfiler_LogError);
}
}


I have an ORM designed db set up. I have turned the Serialization Mode to Unidirectional on the datacontext class (via the design time properties). I also need to turn off deferred loading as is outlined in the following: http://msdn.microsoft.com/en-us/library/bb546184.aspx

However, I can't find out how to do this. I need to set this up via the properties at design time because my ORM model will be on a middle tier using WCF.

How can I turn off deferred loading?
0I also want to use a middle-tier WCF application (in conjunction with the LINQ TO SQL classes I have already set up via the ORM). This will pass data back & forth between the presentation & database tiers.

I'm just confused as to how to set this up :(

I've tried looking at articles specifically about this, but no article I've found actually does this. This is such a basic scenario, that I'm surprised I can't find it anywhere.

I've got the ORM set up (except for the deferred loading being turned off). I need to create the WCF service and integrate it with the ORM project. I need to set up methods in the WCF service for updating data in the database, but am unsure as to how to accomplish this with the ORM LINQ TO SQL classes. I know how to do it using it without the ORM and access the db directly via ado.net, but I want to try and use the ORM LINQ TO SQL classes with the WCF service.

How can I accomplish this. Even some high level bullet points would be appreciated.

Thanks.
--------------------------------------------------------------------------------
Bill Yeager


Bill Yeager

解决方案

There's a property on the datacontext where you can set that: dc.DeferredLoading=false;

I usually override the datacontext constructor in a partial class and set up stuff like deferred loading but also auditing, logging etc in there - that way I can control from code whether I want it or not. (Sometimes I do want deferred loading for stuff that is internal to a WCF service, i.e. the objects will not travel over the wire...)

E.g.:

public SomeDataContext(string connectString, bool enableProfiling, bool disconnect, Guid userID)
    : this(connectString)
{
    _currentUserID = userID;

    if (disconnect == true)
    {
        this.DeferredLoadingEnabled = false;
    }

    if (enableProfiling == true)
    {
        string profilerOutput = Settings.ProfilerOutput;
        _profiler = this.BeginProfiling(profilerOutput, new PageReadFilter(10000), ExecutionPlanMode.Estimated, true);
        _profiler.LogError += new EventHandler(L2SProfiler_LogError);
    }
}


这篇关于ORM与WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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