Skip to content
Advertisement

How to update two columns with same name from two tables in a join query

I am getting an error:

Property or Indexer cannot be assigned to “–” it is read only

when trying to update two columns with the same name in two tables in a join query. How do I get this to work? Thanks!

enter image description here

Advertisement

Answer

The anonymous object created in your projection (“select new” part) is read-only and its properties are not tracked by data context by any means.

Instead, you can try this:

//...
select new 
{
    p1 = p,
    p2 = t
}

foreach (var row in updates)
{
    row.p1.Processed = true;
    row.p2.Processed = true;
}

In order to improve performance you may also want to take a look at batch update capabilities of Entity Framework Extensions (if you are using Entity Framework): https://entityframework-extensions.net/overview

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement