Accessing object properties

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

I'm looking for a way to create a generic function that will take a LinqToSql
object, a Field name and a value that will assign the value to the field. is
this possible?
 
Kevin said:
I'm looking for a way to create a generic function that will take a LinqToSql
object, a Field name and a value that will assign the value to the field. is
this possible?

Sure, but it has nothing to do with LINQ to SQL. If you have any object, you
can manipulate it through reflection -- Type.GetProperty() and friends
should do the trick.

Be aware that reflection carries a significant performance penalty. The
point of LINQ to SQL is to bridge the gap between objects and tables by
allowing strongly-typed access to the underlying database. If you're going
to use generic "set X to Y" logic, you're throwing away the benefits and you
might as well stick to using DataTable, which was made for just such an
approach.
 
Back
Top