I am try to build a linq to get values from a table in sql server that concats 2 fields in different format, DateTime and Int, into one string. Ie.:
var result = from a in db.tbTable select new { a.field1, Description = a.DateTimeField.Value.ToShortDateString() + " - " + a.Cod_filed };
Also, if one of those, or both, of the fields (DateTime and Int) are null? Do i need to do anything else?
Thanx to开发者_JS百科 all
If both DateTimeField
and Cod_filed
are Nullable
then you can try
var result = from a in db.tbTable
select new
{
a.field1,
Description = a.DateTimeField.HasValue
? a.DateTimeField.Value.ToShortDateString()
: string.Empty + " - "
+ a.Cod_filed ?? string.Empty
};
精彩评论