0
I’m having trouble with the following line of code:
var key = entity.GetType().GetProperties().FirstOrDefault(p => p.Name.ToLower().Contains("id")).GetValue(this, null);
Every time he gets on this line he throws an exception
Object does not match the destination type.
The whole method is this:
public void AddOrUpdate(TEntity entity)
{
var key = entity.GetType().GetProperties().FirstOrDefault(p => p.Name.ToLower().Contains("id")).GetValue(this, null);
if (entity == null)
throw new ArgumentNullException("entity");
if ((int)key == 0)
{
_entities.Set<TEntity>().Add(entity);
}
else
{
_entities.Entry(entity).State = EntityState.Modified;
}
}
See if it helps: http://answall.com/questions/44846/obten-valores-de-propriedades-de-class
– rodrigorf
It won’t be because I’m wearing
.GetValue(this, null)
? Thethis
shouldn’t beentity
?– Omni