[RESOLVED]Set IEnumerable content

I have a list like

 IEnumerable<DGeneralAmenities> VBagmodel = (from c in realContext.GeneralAmenities
                                                     select new DGeneralAmenities
                                                         AmenitiesId = c.AmenitiesId,
                                                         Name = c.Name,                                                    
                                                         BActive =c.BActive  ,
checked= //true or false value } ).Where(d => d.BActive == true);

i need to set "checked" entry based on database value .My db contain id of only checked items ie [ 2,5,12,22  ]

please help me how can i set True For only these Id  in VBagmodel

It’s somewhat hard to answer your question because it’s not very clear.

Are you saying there is a nullable id on the model?

If so, you can say 

checked = c.Amenities.HasValue

If that is not correct please add more information to your question.

I need to set true or false based on Database value
And my Db contan GeneralAmenities -Varchar(200) [For Save my Selected Check box Ids -Separated by comma  ie -2,5,4]

IEnumerable LIST
 AmenitiesId    Name    BActive    checked
1                     Wifi         true          
2                     CAR         true            
3                     CC          true          
4                     ABC        true        
5                     DEF         true
My Db contain Amenities=>2,3,5
And How I can i get Result in this form
 AmenitiesId    Name    BActive    checked
1                     Wifi          true           flase 
2                     CAR         true            true
3                     CC           true           true
4                     ABC         true           false
5                     DEF         true             true


Base on your reply, I don’t know where do you get the selected ID value. You could refer to this code below to achieve your requirement.


string[] ids=new string[3];
            MessageInfoEntities1 db = new MessageInfoEntities1();
            var d = (from u in db.UserInfoes
                    select new { Name = u.UserName, Password = u.Pwd, IsChecked = ids.Any(id=>id==u.Pwd)}).ToList();

Best Regards


Leave a Reply