mardi 13 juin 2017

Linq if list null return null

I need a way to if the BeveragesList!= null to field the model, but if is null to put BeverageList = null. I try something like this:

 BeveragesList = su.Wine != null ? new List<BeverageModel>() 
                {
                    new BeverageModel()
                    {
                        Name = su.Wine.name,
                        ShortName =  su.Wine.shortName,
                        Price =  su.Wine.price,
                        Description = su.Wine.description,
                        AlcoholContent = su.Wine.alcoholContent,
                        Region =  su.Wine.Region.name,
                        WineCaste =  su.Wine.wineCaste,
                        UrlImageList = f.Select(i => _url+i.Image.urlImage).ToList(),
                    }
                }: null

I'm always getting an error, I try a lot of things. Soz for beeing newbieee.

Aucun commentaire:

Enregistrer un commentaire