Processing a property in linq to sql
- by Mostafa
Hi
It's my first LINQ TO SQL Project , So definitely my question could be naive .
Till now I used to create new property in Business Object beside of every DateTime Property , That's because i need to do some processing in my DateTime property and show it in special string format for binding to UI Controls .Like :
private DateTime _insertDate;
///
/// I have "InertDate" field in my Table on Database
///
public DateTime InsertDate
{
get { return _insertDate; }
set { _insertDate = value; }
}
// Because i need to do some processing I create a readonly string property that pass InsertDate to Utility method and return special string Date
public string PInsertDate
{
get { return Utility.ToSpecialDate(_insertDate); }
}
My question is I don't know how to do it in LINQ . I did like follow but i get run time error.
ToosDataContext db = new ToosDataContext();
var newslist = from p in db.News
select new {p.NewsId,p.Title,tarikh =MD.Utility.ToSpecialDate( p.ReleaseDate)};
GridView1.DataSource = newslist;
GridView1.DataBind();