Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi All ,

I am trying to defining user defined column in linq for , the below bolder code its returning , i want to define new column StateNameCode its user definesd like alias name sqlserver, getting error

public DataTable GetStates(int StateiD)
{
var dtStates = new DataTable();
try
{
using (var db = new Mydatabaseentitites())
{
var drstates = (from pl in db.Places
join st in db.States on pl.StateID equals st.StateId
join c in db.country on st.CountryId equals c.CountryId
where (st.StateId == StateiD)

select new
{
o.StateID,
o.StateName,
StateNameCode = o.StateName + '{' + o.StateID+ '}'
}
).Distinct().GetDataTable();
if (drstates.Rows.Count > 0)
{
dtStates = drstates;
return dtStates;
}
return dtStates;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
Posted
Updated 8-Sep-14 23:53pm
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900