我有这个简单的 SQL:
SELECT name, value
FROM table1 t1, table2 t2
WHERE t1.id = t2.id
AND t1.id = 123
Run Code Online (Sandbox Code Playgroud)
如何在 C# 中将其转换为 LINQ,以便结果在 Dictionary 中?
我猜你在使用实体框架?你可以改用RelationShips吗?
或者像这样:
var query = from t1 in context.Table1
from t2 in context.Table2
where t1.Id == t2.Id
select new { t1.name, t2.value};
var result = query.ToList();
var dir = result.ToDictionary(x => x.name, x => x.value);
Run Code Online (Sandbox Code Playgroud)
https://docs.microsoft.com/en-us/ef/core/querying/complex-query-operators
| 归档时间: |
|
| 查看次数: |
37 次 |
| 最近记录: |