none
setting a value using MetaDataMember.MemberAccessor.SetBoxedValue RRS feed

  • Question

  • Hi here:

    I'm trying to set a value to an entity member using MetaDataMember.MemberAccessor.SetBoxedValue.

    Suppose the property is Fld_ContactName, my code looks like this:

    object value;

    foreach (MetaDataMember member in db.Mapping.GetTable(EntityObjectInstance.GetType()).RowType.DataMembers))
    {
         value = member.MemberAccessor.GetBoxedValue(EntityObjectInstance);

         if (member.MappedName == "Fld_ContactName")
         {
               member.MemberAccessor.SetBoxedValue(ref value, "Bob");
         }
    }

    The problem is that SetBoxedValue expects the whole EntityObjectInstance as the ref parameter, this would set the whole Entity object as "Bob" (I guess!, I don't want to damage the database), but, how do I set a value to the Fld_ContactName member only?

    Thanks in advance.

    Rafaell


    Believe you can do it, and you will!!
    Thursday, October 15, 2009 12:47 PM

Answers

  • i did it:

    object
    value;

    foreach (MetaDataMember member in db.Mapping.GetTable(EntityObjectInstance.GetType()).RowType.DataMembers)
    {
       if (member.MappedName == "Fld_ContactName")
       {
          value = EntityObjectInstance;
          member.MemberAccessor.SetBoxedValue(ref value, "Bob");
       }
    }


    Believe you can do it, and you will!!
    • Marked as answer by Yichun_Feng Monday, October 19, 2009 8:34 AM
    Thursday, October 15, 2009 6:04 PM