Accessing object properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?S2V2aW4=?=

    Accessing object properties

    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?
  • Jeroen Mostert

    #2
    Re: Accessing object properties

    Kevin wrote:
    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.GetPropert y() 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.

    --
    J.

    Comment

    Working...