0

我们正在为我们当前的项目试验几个不同的持久层。我们正在尝试一种 POCO/PI 方法。我们的候选人之一是 LinqToSql。我正在关注 Vijay Mehta 在“Pro LINQ Object Relational Mapping with C# 2008”中提出的工作,其中 POCO 和映射文件是手动创建的。

我有以下 POCO:

namespace CIN.CIN2010.DomainModel.Notifications
{
    public abstract class Notification //: Repository.BaseEntity
    {

        public Notification(int notificationId, OwnerTag owner, DateTime creationDateTime, string message)
        {
            this._notificatonId = notificationId;
            this._owner = owner;
            this._creationDateTime = creationDateTime;
            this._message = message;
        }

        // omitted for brevity
    }
}

我有一个映射文件:

<Database Name="CINFulfillment" xmlns="http://schemas.microsoft.com/linqtosql/mapping/2007">
  <Table Name="dbo.tblNotifications" >
      <Type Name="CIN.CIN2010.DomainModel.Notifications.Notification, CIN.CIN2010.DomainModel" InheritanceCode="0" IsInheritanceDefault="true">
        <Column Name="NotificationID" Member="NotificationID" Storage="_NotificationID" DbType="Int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" AutoSync="OnInsert" />
        <Column Name="NotificationTypeID" Member="NotificationTypeID" Storage="_NotificationTypeID" DbType="TinyInt NOT NULL" />
        <Column Name="OwnerID" Member="OwnerID" Storage="_OwnerID" DbType="Int NOT NULL" />
        <Column Name="OwnerTypeID" Member="OwnerTypeID" Storage="_OwnerTypeID" DbType="TinyInt NOT NULL" />
        <Column Name="SubTypeID" Member="SubTypeID" Storage="_SubTypeID" DbType="TinyInt NOT NULL" />
        <Column Name="CreationDateTime" Member="CreationDateTime" Storage="_CreationDateTime" DbType="SmallDateTime NOT NULL" />
        <Column Name="Message" Member="Message" Storage="_Message" DbType="VarChar(255) NOT NULL" CanBeNull="false" />
        <Column Name="RequiresAction" Member="RequiresAction" Storage="_RequiresAction" DbType="Bit NOT NULL" />
        <Column Name="ActionTypeID" Member="ActionTypeID" Storage="_ActionTypeID" DbType="TinyInt" />
        <Column Name="DueDateTime" Member="DueDateTime" Storage="_DueDateTime" DbType="SmallDateTime" />
        <Column Name="CompletedDateTime" Member="CompletedDateTime" Storage="_CompletedDateTime" DbType="SmallDateTime" />
        <Column Name="CompletedStatusID" Member="CompletedStatusID" Storage="_CompletedStatusID" DbType="TinyInt NOT NULL" />
      </Type>
  </Table>
</Database>

当我尝试加载映射源时,出现错误:

失败的 CanInstantiateDataContext CIN.CIN2010.Persistence.L2S.Test 测试方法 CIN.CIN2010.Persistence.L2S.Test.ContextTests.CanInstantiateDataContext 抛出异常:System.TypeInitializationException:“嵌套”的类型初始化程序抛出异常。---> System.InvalidOperationException:映射问题:无法解析“CIN.CIN2010.DomainModel.Notifications.Notification”类型的根目录。

有任何想法吗?

4

1 回答 1

1

从 Name 属性中删除“, CIN.CIN2010.DomainModel”。Linq to SQL 查找程序集本身。

于 2010-11-29T13:16:38.067 回答