Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Update multiple records using dynamic property name(reflection)

$
0
0

Hi All,

I wanna update the specific property value by using reflection, and I used to iterate each row and update the value then finally submit to savechanges.

It takes some time to process all the things.

filter condition for fetch only required records

{

PropertyInfo _propertyName= orderToUpdate.GetType().GetProperty("CollumnName", BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
if( propertyName != null)
{
  Type type = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
   object valueToUpdate = Convert.ChangeType(x.ColumnValue, type);
  prop.SetValue(valueToUpdate , 1000, null);
}
}
 _context.SaveChanges();

There is any way to handle this bulk edit by using property reflection instead of checking each record property match.

Thanks,


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>