EntityRef is a property that represents the other end of a relationship. We have set
the Items as EntitySet within the Categories entity class. The other side of the
relationship, that is, the Items entity class, should also define its relationship
with the Categories entity. EntityRef is used for giving the reference between the
entity classes.
LINQ to SQL
[ 86 ]
[Table(Name="Categories")]
public class Categories
{
[Column(Name = "CategoryID", Id=true, AutoGen=true,
DBType="int NOT NULL IDENTITY")]
public int CategoryID;
[Column(Name = "Category", DBType="nvarchar(1000)")] //,
UpdateCheck=UpdateCheck.Always)]
public string Category;
[Column(Name="Description", DBType="nvarchar(1000)")] // ,
UpdateCheck=UpdateCheck.Always)]
public string Description;
private EntitySet
_Items;
[Association(Storage="_Items", OtherKey="CategoryID")]
public EntitySet Items
{
get { return this._Items; }
set { this._Items.Assign(value); }
}
public Categories() { this._Items = new EntitySet(); }
}
[Table(Name="Items")]
public class Items
{
[Column(Name = "ItemID", IsPrimaryKey = true, IsDbGenerated =
true, DbType = "int NOT NULL IDENTITY", CanBeNull = false)]
public int ItemID { get; private set; }
[Column(Name = "CategoryID")]
public int CategoryID { get; set; }
[Column(Name = "Name", DbType = "nvarchar(1000)")]
public string Name { get; set; }
[Column(Name = "Ingredients", DbType = "nvarchar(1000)")]
public string Ingredients { get; set; }
??¦
??¦
??¦
[Association(Storage = "_Categories", ThisKey = "CategoryID")]
public Categories Categories
{
get { return this.
Pages:
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151