代码之家  ›  专栏  ›  技术社区  ›  egyedg

Linq2Sql可空关联

  •  0
  • egyedg  · 技术社区  · 14 年前

    在多语言项目中,我在SQL2005中有以下数据库结构:

    表StringTable:

       itemID int PK,
       stringID int NOT NULL,
       stringValue nvarchar,
       languageId int
    

    桌面文章:

       articleID int PK,
       titleID int NOT NULL (FK to StringTable.stringID),
       descriptionID int NULL (FK to StringTable.stringID)
    

    映射项目时遇到问题。在Linq2Sql中,descriptionID->StringTable.stringID关联(使用设计器)。。是说:“如果子属性可以为空,则父属性不能为空”。。。我明白。。。但在我的情况下,descriptionID必须是可以为空的。 有谁能帮我解决这个问题或提出一个解决方案(使用L2Sql和C#),如果有帮助的话,我也愿意修改数据库结构。

    我只需要一个Article对象的Descriptions属性,它包含给定Article的描述(所有语言)或NULL。

    1 回复  |  直到 14 年前
        1
  •  0
  •   Tristan    14 年前

    有同样的问题-通过将关联添加到另一个表中来解决。