本来想在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);