I’m using VS 2010 and LinqToSql. When I drag a view onto the diagram and set my relations, the XML is updated but the class does not get updated with the supporting methods and properties.
Before when I’ve done this, I would get a property like so:
[global::System.Data.Linq.Mapping.AssociationAttribute(Name="Question_QuestionAggregatesView", Storage="_QuestionAggregatesView", ThisKey="Id", OtherKey="Id", IsUnique=true, IsForeignKey=false)]
[global::System.Runtime.Serialization.DataMemberAttribute(Order=38, EmitDefaultValue=false)]
public QuestionAggregatesView QuestionAggregates
{
get
{
if ((this.serializing
&& (this._QuestionAggregatesView.HasLoadedOrAssignedValue == false)))
{
return null;
}
return this._QuestionAggregatesView.Entity;
}
set
{
QuestionAggregatesView previousValue = this._QuestionAggregatesView.Entity;
if (((previousValue != value)
|| (this._QuestionAggregatesView.HasLoadedOrAssignedValue == false)))
{
this.SendPropertyChanging();
if ((previousValue != null))
{
this._QuestionAggregatesView.Entity = null;
previousValue.Question = null;
}
this._QuestionAggregatesView.Entity = value;
if ((value != null))
{
value.Question = this;
}
this.SendPropertyChanged("QuestionAggregates");
}
}
}
But LinqToSql didn’t create this type of property for my newly added view.
Is this a bug in VS2010 or am I doing something wrong?
Thanks so much!!
Found the answer after some sophisticated search engine query manipulation:
http://www.bartlannoeye.com/blog/linq-to-sql-not-generating-code-for-association
Thanks Bart Lannoeye for your helpful post. In short, because I added a view to the diagram, a primary key wasn’t added by default. I had to specify the primary key for the view in the diagram, and all worked fine after that.