LINQ2SQL、持久性无知和域模型

发布于 2024-08-20 14:52:55 字数 149 浏览 5 评论 0原文

这里有没有人使用过LINQ to SQL来支持域的持久化 型号?

我不打算使用 LINQ2SQL 实体设计器,而只是使用普通的手动编码 XML 映射,并且目前遇到了障碍。

我尝试在我正在做的 DDD 示例中使用它,因为我的观众只知道 LINQ2SQL。

Has anyone here have used LINQ to SQL to support the persistence of domain
models?

I'm not planning to use the LINQ2SQL entity designer, just plain-old hand-coded XML mapping and I'm currently having roadblocks.

I'm attempting to use it in a DDD example I'm doing, since my audience only knows LINQ2SQL.

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

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

发布评论

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

评论(1

狼性发作 2024-08-27 14:52:55

POCO 可以进行映射,因此可以与 DataContext 一起使用。

但是,我发现映射有点泄漏。数据模型信息现在正在泄漏到域实体。考虑这个例子:

    <Table Name="dbo.products">
    <Type Name="Ptc.Store.Core.Product">
        <Column Name="id" Member="Id" IsDbGenerated="true" IsPrimaryKey="true" CanBeNull="false" DbType="INT NOT NULL IDENTITY" />
        <Column Name="name" Member="Name" CanBeNull="false"  DbType="VARCHAR(50) NOT NULL" />
    </Type>
</Table>

<Table Name="[dbo].branches">
    <Type Name="Ptc.Store.Core.Branch">
        <Column Name="id" Member="Id" IsDbGenerated="true" IsPrimaryKey="true" DbType="INT NOT NULL IDENTITY" />
        <Column Name="name" Member="Name" CanBeNull="false" DbType="VARCHAR(50) NOT NULL" />
    </Type>
</Table>

<Table Name="[dbo].sales">
    <Type Name="Ptc.Store.Core.Sale">
        <Column Name="id" Member="Id" IsDbGenerated="true" IsPrimaryKey="true" CanBeNull="false" DbType="INT NOT NULL IDENTITY" />
        <Column Name="transaction_date" Member="TransactionDate" CanBeNull="false" DbType="DATETIME" />
        <Column Name="amount" Member="Amount" CanBeNull="false" DbType="MONEY" />
        <Association Name="sales_item" Member="Item" IsForeignKey="true" ThisKey="ProductId" OtherKey="Id"  />
        <Association Name="sales_location" Member="Location" IsForeignKey="true" ThisKey="BranchId" OtherKey="Id" />

        <!-- Why do I have to map foreign keys? Looks leaky to me.-->
        <Column Name="product_id" Member="ProductId" CanBeNull="false" DbType="INT" />
        <Column Name="branch_id" Member="BranchId" CanBeNull="false" DbType="INT" />
    </Type>
</Table>

更糟糕的是我必须显式声明实体的属性以匹配数据模型的外键。我不必使用 NHibernate 来执行此操作。

有没有更好的方法可以在不显式写入属性及其到数据模型的映射的情况下执行此操作?

POCOs can be mapped so it can be used with a DataContext.

However, I find the mapping a bit leaky. Data model information is now leaking to the domain entity. Consider this example:

    <Table Name="dbo.products">
    <Type Name="Ptc.Store.Core.Product">
        <Column Name="id" Member="Id" IsDbGenerated="true" IsPrimaryKey="true" CanBeNull="false" DbType="INT NOT NULL IDENTITY" />
        <Column Name="name" Member="Name" CanBeNull="false"  DbType="VARCHAR(50) NOT NULL" />
    </Type>
</Table>

<Table Name="[dbo].branches">
    <Type Name="Ptc.Store.Core.Branch">
        <Column Name="id" Member="Id" IsDbGenerated="true" IsPrimaryKey="true" DbType="INT NOT NULL IDENTITY" />
        <Column Name="name" Member="Name" CanBeNull="false" DbType="VARCHAR(50) NOT NULL" />
    </Type>
</Table>

<Table Name="[dbo].sales">
    <Type Name="Ptc.Store.Core.Sale">
        <Column Name="id" Member="Id" IsDbGenerated="true" IsPrimaryKey="true" CanBeNull="false" DbType="INT NOT NULL IDENTITY" />
        <Column Name="transaction_date" Member="TransactionDate" CanBeNull="false" DbType="DATETIME" />
        <Column Name="amount" Member="Amount" CanBeNull="false" DbType="MONEY" />
        <Association Name="sales_item" Member="Item" IsForeignKey="true" ThisKey="ProductId" OtherKey="Id"  />
        <Association Name="sales_location" Member="Location" IsForeignKey="true" ThisKey="BranchId" OtherKey="Id" />

        <!-- Why do I have to map foreign keys? Looks leaky to me.-->
        <Column Name="product_id" Member="ProductId" CanBeNull="false" DbType="INT" />
        <Column Name="branch_id" Member="BranchId" CanBeNull="false" DbType="INT" />
    </Type>
</Table>

The worse part is that I have to explicitly declare properties on my entities to match the data model's foreign keys. I didn't have to do this with NHibernate.

Is there any better way to do this without explicitly writing properties and their mapping to the data model?

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