类型化数据集和 Dtos

发布于 2024-07-18 02:00:08 字数 233 浏览 7 评论 0原文

我有一个连接到 WCF 服务以实现其业务逻辑的 Web 应用程序。 出于性能和互操作性的原因,我想使用简单的 Dto 在 WCF 边界传输数据。

但是,我必须使用类型化数据集进行数据访问(由于政治原因,ORM 或任何其他选项不可用)。

将 Dto 与类型化数据集一起使用是个好主意吗? 有人这样做过吗? 有推荐的模式吗? 最重要的是,是否有一个库/工具/方法可以从类型化数据集中自动生成 Dto?

I have a web application that connects to WCF services for its business logic. I would like to use simple Dto's for transfering data at the WCF boundary for performance and interoperability reasons.

However I have to use typed datasets for data access (ORM or any other option is not available due to political reasons).

Is it a good idea to use Dto's along with typed datasets. Have anyone done this? Is there a recommended pattern? And most importantly is there a library/tool/method to auto generate Dto's from the typed datasets?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夕嗳→ 2024-07-25 02:00:08

我想到了实体翻译模式。
http://msdn.microsoft.com/en-us/library/cc304747.aspx
好吧,也许是它的一个变体。

我最近必须做一些类似的事情,我刚刚创建了另一个“层”,它将存储在数据行/数据表等中的数据转换为数据契约对象。 服务层可以使用数据访问方法的结果作为参数来调用这个新的层方法。

这是一个快速而肮脏的 PSUEDOCODE 示例:

 public class personTranslator
 {

     public static PersonDataContract TranslateToContract(Datarow personDataRow)
    {
        PersonDataContract resultPerson = new Person;
        resultPerson.FirstName = personDataRow["FirstName"];
        resultPerson.LastName = personDataRow["LastName"];
        .
        .
        [etc.]

        return resultPerson;
    }
 }

SERVICELAYER Class

 public PersonDataContract GetSpecificPerson([Parameters])
 {
     [other setup/validation code...]
    return   PersonTranslator.TranslateToContract(PersonDataAccess.GetPersonRow([Parameters]));
 }

Entity translation pattern comes to mind.
http://msdn.microsoft.com/en-us/library/cc304747.aspx
Well, maybe a variation on it.

I had to do something similiar recently, and I just created a another "layer" that translates the data stored in the datarow/datatable etc. into the data contract object. The service layer can call this new layer method with the results from your data-access method as a parameter.

Here's a quick and dirty PSUEDOCODE example:

 public class personTranslator
 {

     public static PersonDataContract TranslateToContract(Datarow personDataRow)
    {
        PersonDataContract resultPerson = new Person;
        resultPerson.FirstName = personDataRow["FirstName"];
        resultPerson.LastName = personDataRow["LastName"];
        .
        .
        [etc.]

        return resultPerson;
    }
 }

SERVICELAYER Class

 public PersonDataContract GetSpecificPerson([Parameters])
 {
     [other setup/validation code...]
    return   PersonTranslator.TranslateToContract(PersonDataAccess.GetPersonRow([Parameters]));
 }
苏别ゝ 2024-07-25 02:00:08

我建议使用类型化的 DataRow-s、DataTable-s。 类型化 DataRow 和 Dto 对象之间实际上没有太大区别。
就性能而言,您必须测试普通 Dto-s 是否会有所帮助(我对此表示怀疑)。
至于互操作性,类型化 DataRow-s 是普通类,因此它们与 Dto 对象一样具有互操作性。

I would suggest to use typed DataRow-s, DataTable-s. There's really not much difference between a typed DataRow and a Dto object.
Performance wise you have to test it that plain Dto-s will help (I doubt it).
As for interoperability, typed DataRow-s are plain classes, so they are as interoperable as Dto objects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文