Question

I'm trying to follow the ASP.NET Nerd Dinner tutorial of Microsoft, but I'm having problems with the linq-to-sql part.

I have the two databases Dinner and RSVP with primary keys and identity set to DinnerID and RsvpID. Then I created the relation FK_RSVP_Dinner with foreign key RSVP.DinnerID and pk Dinner.DinnerID

When creating the LinqToSql class and drag the two tables in, it creates the OneToMany relation successfully.

LinqToSql Class However, the NerdDinner.designer.cs file does not contain any collection called RSVPs, but only a variable RSVP.

enter image description here

What am I doing wrong?

Was it helpful?

Solution

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top