【问题标题】:PLINQO Primary key AND index problemPLINQO 主键和索引问题
【发布时间】:2010-08-23 20:22:50
【问题描述】:

我有两个表,Profile 和 ProfileCategory

ProfileId INT IX
UserId UNIQUEIDENTIFIER PK (For one-to-one mapping with aspnet_membership)
CompanyName
Description

ProfileCategory
CategoryId
ProfileId

当我使用 PLINGO 生成代码时,出现以下错误

运算符“==”不能应用于“int?”类型的操作数和'System.Guid' 运算符“==”不能应用于“int?”类型的操作数和'System.Guid'

我深入研究了生成的代码和以下内容..

    [System.Diagnostics.DebuggerNonUserCode]
    [System.CodeDom.Compiler.GeneratedCode("CodeSmith", "5.0.0.0")]
    private void OnProfileList1Remove(Profile entity)
    {
        SendPropertyChanging(null);
        var profileCategory = ProfileCategoryList.FirstOrDefault(c => c.CategoryId == CategoryId
            && c.ProfileId == entity.UserId);
        ProfileCategoryList.Remove( profileCategory);
        SendPropertyChanged(null);
    }

所以生成的代码好像要比较索引和主键

我可以手动更改代码,但在重新生成时它将被更改回来。

有人知道为什么会这样吗?

谢谢

这是来自 dbml 的配置文件片段

    <Table Name="dbo.Profile" Member="Profile">
        <Type Name="Profile">
          <Column Name="UserId" Storage="_userId" Type="System.Guid" DbType="uniqueidentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
          <Column Name="ProfileId" Storage="_profileId" Type="System.Int32" DbType="int NOT NULL IDENTITY" CanBeNull="false" />
          <Column Name="CompanyName" Storage="_companyName" Type="System.String" DbType="nvarchar(250) NOT NULL" CanBeNull="false" />
          <Column Name="Description" Storage="_description" Type="System.String" DbType="varchar(MAX)" CanBeNull="true" />
          <Column Name="Services" Storage="_services" Type="System.Xml.Linq.XElement" DbType="xml" CanBeNull="true" UpdateCheck="Never" />
          <Column Name="ContactDetails" Storage="_contactDetails" Type="System.Xml.Linq.XElement" DbType="xml" CanBeNull="true" UpdateCheck="Never" />
          <Column Name="Attributes" Storage="_attributes" Type="System.Xml.Linq.XElement" DbType="xml" CanBeNull="true" UpdateCheck="Never" />
          <Column Name="StateId" Storage="_stateId" Type="System.Int32" DbType="int NOT NULL" CanBeNull="false" />
          <Column Name="Views" Storage="_views" Type="System.Int32" DbType="int NOT NULL" CanBeNull="false" />
          <Association Name="User_Profile" Member="User" Storage="_user" ThisKey="UserId" Type="User" IsForeignKey="true" DeleteRule="CASCADE" />
          <Association Name="Profile_ProfileAddress" Member="ProfileAddressList" Storage="_profileAddressList" OtherKey="UserId" Type="ProfileAddress" DeleteOnNull="false" />
          <Association Name="Profile_Review" Member="ReviewList" Storage="_reviewList" ThisKey="ProfileId" OtherKey="ProfileId" Type="Review" DeleteOnNull="false" />
          <Association Name="Profile_ProfileCategory" Member="ProfileCategoryList" Storage="_profileCategoryList" ThisKey="ProfileId" OtherKey="ProfileId" Type="ProfileCategory" />
        </Type>
 </Table>
 <Table Name="dbo.ProfileCategory" Member="ProfileCategory">
    <Type Name="ProfileCategory">
      <Column Name="ProfileCategoryId" Storage="_profileCategoryId" Type="System.Int32" DbType="int NOT NULL IDENTITY" IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
      <Column Name="ProfileId" Storage="_profileId" Type="System.Int32" DbType="int" CanBeNull="true" />
      <Column Name="CategoryId" Storage="_categoryId" Type="System.Int32" DbType="int NOT NULL" CanBeNull="false" />
      <Association Name="Category_ProfileCategory" Member="Category" Storage="_category" ThisKey="CategoryId" Type="Category" IsForeignKey="true" />
      <Association Name="Profile_ProfileCategory" Member="Profile" Storage="_profile" ThisKey="ProfileId" OtherKey="ProfileId" Type="Profile" IsForeignKey="true" DeleteRule="CASCADE" />
    </Type>
  </Table>

【问题讨论】:

  • 您是否检查过外键 ProfileCategory.ProfileId 引用了 Profile.ProfileId ?
  • 是的。我已经签入了 dbml 文件,并在数据库中删除并重新创建了外键关系。

标签: indexing primary-key codesmith plinqo


【解决方案1】:

您是否检查过以确保 PLINQO 的夜间版本中尚未修复此问题?能否请您发布这两个表的架构(或发送给 CodeSmith 支持)。

谢谢 -布莱克·涅米斯基

【讨论】:

  • 刚做了这个,但没有用。我尝试在我当前的项目上运行它,并且我还生成了一个新项目也失败了。我查看了 Entity.Generated.cst,它似乎将单独的 PK 和 IX 混淆为多对多关系。
  • 我将添加上面的架构。谢谢
  • 您好,您可以在哪里添加架构?谢谢 -Blake Niemyjski
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-20
  • 2010-10-02
  • 1970-01-01
  • 1970-01-01
  • 2010-11-01
  • 1970-01-01
相关资源
最近更新 更多