This question is about this code:
entityEntry.Property("WhateverProperty").CurrentValue = 1;
I answered this question yesterday and if you notice in the comments to the question (not the answer), one of the members @gertarnold said this:
entityEntry.Property("InsertedBy") doesn't use reflection, it reads the EF metadata.
Sure it uses the EF metadata to figure out if the entity has that property but I am pretty sure somewhere down the line they would have to use reflection to set the property.
I tried looking at the source code here, here and here (line 484) and then chickened out.
So the questions are:
- Does it use reflection?
- If not, how is the property set then?
ctx.Entry(someEntity).Property("WhateverProperty").CurrentValue = 1;and observe that value ofsomeEntity.WhateverPropertyhas changed, which could not be done without some form of reflection. Though of course all reflection is cached (in form of compiled delegates), so it's not actually that slow - there is nothing likeGetProperty("WhateverProperty").SetValue(entity, 1)every time you do this.