Replace Linq to Entity value in Projection
I want to relace a value retrieved from a L2E projection to an expanded string.
The table contains a column called Status which can have a value "0" or "1" and in my L2E I have
var trans = from t in db.Donation
select new DonationBO()
{
开发者_如何学Python Status = t.Status
};
What I want is to return either of the strings "Pending" or "Committed" instead of "0" or "1".
How can I do this here?
If Status is a string you could simply do:
var trans = from t in db.Donation
select new DonationBO()
{
Status = t.Status == "0" ? "Pending" : "Committed"
};
精彩评论