0

我正在尝试遵循 Microsoft 的 ASP.NET Nerd Dinner 教程,但我遇到了 linq-to-sql 部分的问题。

我有两个数据库 Dinner 和 RSVP,主键和身份设置为DinnerIDand RsvpID。然后我FK_RSVP_Dinner用外键RSVP.DinnerID和pk创建了关系Dinner.DinnerID

在创建 LinqToSql 类并将两个表拖入时,它成功创建了 OneToMany 关系。

LinqToSql 类 但是,NerdDinner.designer.cs 文件不包含任何称为 RSVP 的集合,而仅包含一个变量 RSVP。

在此处输入图像描述

我究竟做错了什么?

4

1 回答 1

1

Couple of things to check:

Look in the NerdDinner.dbml's designer.cs file under the RSVP partial class definition and the Dinner partial class definition:

public partial class RSVP....

  1. Make sure RsvpID is an Identity type of Primary Key with auto-generation of the key.

[Column(Storage="_RsvpID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]

  1. A private EntityRef type should have been generated:

private EntityRef _Dinner;

  1. Check the association property: [Association(Name="Dinner_RSVP", Storage="_Dinner", ThisKey="DinnerID", OtherKey="DinnerID", IsForeignKey=true)] public Dinner Dinner......

Do the same for the Dinner partial class...

  1. Is the primary key correctly defined?
  2. Is a EntitySet _Rsvps defined?
  3. Is there and association defined: [Association(Name="Dinner_RSVP", Storage="_RSVPs", ThisKey="DinnerID", OtherKey="DinnerID")] public EntitySet RSVPs....

Hope that helps...

于 2014-03-12T23:10:35.790 回答