在选择抛出异常时访问透明标识符。
var result = (from t1 in table1
join t2 in table2 on t1.col1 equals t2.col1 into myTable1
from a in myTable1.DefaultIfEmpty()
join t3 in table3 on t1.col2 equals t3.col2 into myTable2
from b in myTable2.DefaultIfEmpty()
where t1.col1 == 1
select new
{
prop1 = b,
prop2 = myTable1,
prop3 = myTable1.Count()
});
异常(exception):variable 'myTable1' of type 'System.Collections.Generic.IEnumerable' referenced from scope '', but it is not defined.
最佳答案
需要用你的结果创建一个类。
请检查以下方式。
PropModel propModel = new PropModel();
propModel = (from t1 in table1
join t2 in table2 on t1.col1 equals t2.col1 into myTable1
from a in myTable1.DefaultIfEmpty()
join t3 in table3 on t1.col2 equals t3.col2 into myTable2
from b in myTable2.DefaultIfEmpty()
where t1.col1 == 1
select new
{
prop1 = b,
prop2 = myTable1.FirstOrDefault(),
prop3 = myTable1.Count()
}).FirstOrDefault();
public class PropModel
{
public table3 prop1 { get; set; }
public table2 prop2 { get; set; }
public Int32 prop3 { get; set; }
}
关于c# - 访问 select 中的透明标识符会引发它不是从范围引用的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69162072/