I don't know that it is possible or not. i have search some links but didn't find the solution.
i have a linq query for getting some data from the database. Now, In my Database in the table column Photo can have or can not have a Image. it means Photo can be null also.
so My Question is: is there a way rather than use if else condition in linq query that we can put my code like this:
DataTable Customer=ds.Tables["Customer"]
if (Photo==null)
{
var items = (from d in Customer.AsEnumerable()
where d.Field<string>("strHin") != string.Empty
orderby d.Field<DateTime>("date")
select new News
{
NewsItemId = d.Field<Int32>("intCustId").ToString(),
HeadLine = d.Field<string>("strHin"),
Photo = null,
}).Take(Convert.ToInt32(limit)).ToList();
return items;
}
if(Photo !=null)
{
var items = (from d in Customer.AsEnumerable()
where d.Field<string>("strHin") != string.Empty
orderby d.Field<DateTime>("date")
select new News
{
NewsItemId = d.Field<Int32>("intCustId").ToString(),
HeadLine = d.Field<string>("strHin"),
Photo = @"http://192.168.1.12:801/ImageById/" + d.Field<Int32>("intCustId") + ".jpg"
}).Take(Convert.ToInt32(limit)).ToList();
return items;
}
i don't want to use if else because i have already used many if else in my code. is there a way that i can use this with linq query without repeatation of code.