简体   繁体   English

了解LINQ与SQL的关联

[英]Understanding associations in linq to sql

Im trying to understand how to use the associations(so that my linq statements are more readable) 我试图了解如何使用关联(以便我的linq语句更易读)

I have a table logs, which has many mapping IDs. 我有一个表日志,其中有许多映射ID。 I have a table with a primary key mapping ID which has permutations of countryID, categoryID, and categoryTypeID. 我有一个带有主键映射ID的表,该ID具有countryID,categoryID和categoryTypeID的排列。 Each of those has that column as a primary key on each of there tables. 每个表都有该列作为每个表的主键。 My understanding is that if i set up my context right i could do something like 我的理解是,如果我设置正确的环境,我可以做类似的事情

(from l in datacontext.logs
where l.mappings.category.barId== myNumber
select l)

But I cant seem to figure out how to make that happen. 但我似乎无法弄清楚该如何实现。 Is it possible, and how could i go about setting up my project to do this. 有可能吗,我该如何设置我的项目来做到这一点。

Can you not use 你不能使用

(from l in datacontext.logs
join m in datacontext.mappings on l.mappingId equals l.mappingid
join c in datacontext.category on m.categoryid equals c.categoryid
where c.barId == myNumber
select l).ToList();

I am making assumptions on your table structure based on your question. 我正在根据您的问题对您的表结构进行假设。

I figured it out, my associations were backwards. 我想通了,我的协会倒退了。 logs is not the parent of mapings, rather mapings is the parent of logs. 日志不是映射的父级,而是映射是日志的父级。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM