For this kind of schema:
mainTable(Id,Name) //Id is primary key
secondryTable(mainTableId,RegDate,Age) // mainTableId is foreign key
Can anyone give me a example of Linq to Sql using navigation properites.
With join I am selecting as:
from mainT in db.mainTable
join secT in db.secondryTable on mainT.Id equals secT.mainTableId
select new { mainT.Name, secT.RegDate, secTable.Age}
I found a solution on my own :) The query would be:
FROM mainT in db.mainTable
SELECT new
{
mainT.Name,
regDate = mainT.secT.Where(//some condition),
age = mainT.secT.Where(//some condition)
}
The above query is valid only if the Primary key/Foreign key relationships are defined properly in database.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.