Linq选择多个列,C#反射获取值

本来想在linq里面通过反射获取值并放入匿名类select出多个列的,失败了,还是分开来吧。

Linq选择多个列

用匿名类型咯

  • var employee = _db.EMPLOYEEs .Where(x => x.EMAIL == givenInfo || x.USER_NAME == givenInfo) .Select(x => new { x.EMAIL, x.ID });
  • var employee = (from res in _db.EMPLOYEEs where (res.EMAIL == givenInfo || res.USER_NAME == givenInfo) select new {res.EMAIL, res.USERNAME} );
  • var employee = (from res in _db.EMPLOYEEs where (res.EMAIL == givenInfo || res.USER_NAME == givenInfo) select new {email=res.EMAIL, username=res.USERNAME} );

反射取值

反射取属性值
car.GetType().GetProperty(propertyName).GetValue(car, null);

Entity Framework vs LINQ to SQL

Entity Framework vs LINQ to SQL 还没看

你可能感兴趣的:(Linq选择多个列,C#反射获取值)