use select columns for calculations RRS feed

  • Question

  • var result = from assc in context.A

    join b in B on .........

    select new classXYZ { total =

    spent = ..............

    Left = total - spent


    I have a linq query which returns an object classXYZ , the column Left, of which is a calculation on other two columns.

    It doesnt allow that calculation.

    Any thoughts on why wont it pick up.

    Second thing is i am trying to use the result object to update that value like

    result.Left = result.Total - result.Spent.

    Why wont this also work?


    Wednesday, October 30, 2013 4:58 PM


  • Hi Raj_Microsoft;

    Modify your select clause to look like the following

    select new classXYZ {
         total = assc.Column2 * b.Column2,
         spent = assc.Cplumn4 - b.Column10,
         Left = (assc.Column2 * b.Column2) - (assc.Cplumn4 - b.Column10)


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by Fred Bao Wednesday, November 6, 2013 7:50 AM
    Wednesday, October 30, 2013 5:22 PM