views:

23

answers:

1

Hello,

I try to convert an anonymous type to class but I don't.

My code in ViewModel :

  <public List**<???>** PoolCondition { get; set; }

        Entities db = new Entities();


        public SelectListViewModel()
        {

            string Lang = SessionManager.Language;    
            var poolcondition = (from ddlv in db.DropDownListValue
                                 from ddlv_t in ddlv.DropDownListValue_Translation
                                 where ddlv_t.Language.code == Lang                                 
                                 select new { ddlv.Id, ddlv_t.Traduction }).ToList();

            PoolCondition = poolcondition;

I've an error width PoolCondition=poolcondition, because poolcondition is anonymous type. How to cast my List PoolCondition??

Thank you!

+2  A: 

Rather than creating a list of anonymous types, why not create a list of your objects? Perhaps something like:

var poolcondition = (from ddlv in db.DropDownListValue
                     from ddlv_t in ddlv.DropDownListValue_Translation
                     where ddlv_t.Language.code == Lang
                            //initialize your object appropriately
                     select new PoolCondition { Id = ddlv.Id, Traduction = ddlv_t.Traduction })
                    .ToList();
Jeff M
Yeah, It's work fine!! Thank you
Akawan