none
linq query RRS feed

  • Question

  • Hi, if I have the following code:

    _modelo.VMCentro.Areas.ToList()

    .Where(objModelo => !entidad.Areas.Exists(objEntidad => objEntidad.Idcentro.ToString() == objModelo)).ToList()

    .ForEach(objModelo => entidad.Areas.Add(

    new Area_centro { Idarea = entidad.Id, Idcentro = long.Parse(objModelo), Idcecosap = "here goes a function which give back the value" }));

    How can I do to put inside a function which returns the value?? For example get the value from a dictionary: dictionary.TryGetValue(area.Id.ToString(), out

    idcecosap);

    Thanks.

    Friday, July 22, 2011 2:51 PM

Answers

  • Before of doing the operation in a Foreach, create a new projection (using select) to create a dynamic entity which gets the value of the dictionary in the first member entity like what you specified above and secondly stores the objmodelo as the second property and assign it to a temporary var item.

    After the assignment, do the foreach above which adds the Area_Centro as you show above.

    Then after that foreach on a new line/operation, extract what is needed for the return value of your function.

     

    HTH

     


    William Wegerson (www.OmegaCoder.Com)
    Friday, July 22, 2011 7:30 PM
    Moderator