Nathan
Nathan

Reputation: 1

How in Linq to entity replace true or false with On or Off?

I need to bind grid with linq to entity(asp C#), when Im binding I need to replace true or false with On or Off. how I can accomplish it?

ex.

var t = from k in entity.table select k.IsActive;

so in result if

IsActive == true I need to return On
IsActive == false I need to return Off

Upvotes: 0

Views: 488

Answers (3)

Fooad Karimi
Fooad Karimi

Reputation: 1

try this

var t = from k in entity.table select k.IsActive.GetValueOrDefault() ? "On" : "Off";

Upvotes: 0

Alex Mendez
Alex Mendez

Reputation: 5150

Have you tried this?

var t = from k in entity.table select (k.IsActive ? On : Off); 

Upvotes: 0

cdhowie
cdhowie

Reputation: 169143

var t = from k in entity.table select k.IsActive ? "On" : "Off";

Upvotes: 4

Related Questions