Processing a property in linq to sql

Posted by Mostafa on Stack Overflow See other posts from Stack Overflow or by Mostafa
Published on 2010-04-16T09:00:09Z Indexed on 2010/04/16 9:03 UTC
Read the original article Hit count: 280

Filed under:

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();

© Stack Overflow or respective owner

Related posts about linq-to-sql