Reputation: 476
I have a list data like this
var empData = this._db.empObj
.Where(x => x.Id == 18)
.OrderByDescending(x => x.Name)
.ToList();
Is there a way I can get a specific column data from the db as simple as the above? Something like:
string Name = this._db.empObj.Where(x => x.Id == 18)
Upvotes: 0
Views: 46
Reputation: 2796
You can try Single
or SingleOrDefault
var name = this._db.empObj.SingleOrDefault(x => x.Id == 18)?.Name;
var name = this._db.empObj.Single(x => x.Id == 18).Name;
If you want to get a list of name
var names = this._db.empObj.Where(x => x.Id == 18).Select(x => x.Name);
Upvotes: 2