_employees;}
set { this._employees.Assign(value);}
}
}
[Table(Name = "HumanResources.Employee")]
public class Employee
{
[Column(DBType = "int", IsPrimaryKey = true, IsDBGenerated = true,
CanBeNull = false)]
public int EmployeeID;
[Column(DBType = "int", CanBeNull = false)]
public int ContactID;
[Column(DBType = "nvarchar(256) not null")]
public string LoginID;
[Column(DBType = "nvarchar(15) not null")]
public string NationalIDNUmber;
[Column(DBType = "int")]
public int ManagerID;
}
247
Part III: LINQ to SQL
With the classes and relationship defined, you can now write a LINQ to SQL ??????join??™??™ query that utilizes
the relationship, like this:
IQueryable
conQuery =
from con in db.Contact
where con.Employee.ContactID == 19917
Or like this:
var conQuery =
from con in db.Contact
from emp in con.Emps
where con.FirstName == "Scott"
select new {con.FirstName, emp.ManagerID};
Think of the EntitySet type and the [Association] attribute (utilized in the table mapping above) as
equal to a SQL join.
EntityRef (of TEntity)
The EntityRef type defines a relationship between two tables, but does the opposite of the EntitySet,
in that it provides for the ??????one??™??™ side of a one-to-many relationship.
Pages:
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399