如题:使用LinqExtensions获取到数据后,如何提取其中的某个字段。
var expression = LinqExtensions.True<Plat_DeviceEntity>();
var station = LinqExtensions.True<Plat_StationEntity>();
string OrganizeId = OperatorProvider.Provider.Current().CompanyId;
station = station.And(t => t.OrganizeId.Contains(OrganizeId));
// 我想获取station中的一个字段 如何获取 接下来改如何写了?
求大佬帮助
参考GPT和自己的思路:
如果你想获取station
中的某个字段,可以使用Select
方法来实现。
var expression = LinqExtensions.True<Plat_DeviceEntity>();
var station = LinqExtensions.True<Plat_StationEntity>();
string OrganizeId = OperatorProvider.Provider.Current().CompanyId;
station = station.And(t => t.OrganizeId.Contains(OrganizeId));
var fieldName = "FieldName"; // 要获取的字段名
var result = station.Select(t => t.GetType().GetProperty(fieldName).GetValue(t, null));
这里的GetType().GetProperty(fieldName)
用于通过反射获取station
中的某个属性,再使用GetValue
方法获取该属性的值。最终得到的result
变量就是所需要的字段值了。