none
Update a Field Using a Field Name String RRS feed

  • Question

  • I want to update field update a field based on a field name string as shown below, where emailTimeStampField is a string variable containing the name of a field. However, when I attempt to run this, I get the error shown following the code block.

    Doing this with a RECID which is a long integer does work. So how do I do this sort of thing for a DateTime field, or is that possible?

    var tran = (from t in context.TDYBATCHMONITORINGTRANS
                where t.RECID == batchTransRecId
                select t).SingleOrDefault();
    
    context.Entry(tran).Property(emailTimeStampField).CurrentValue 
    = DateTimeOffset.UtcNow.DateTime;
    
    int result = context.SaveChanges();
    
    
    


                   

    Friday, September 19, 2014 11:48 PM

Answers

  • My apologies. The problem turned out to be a programmer error. The string needed to be fully capitalized to match the data model.

    This does indeed work.

    Saturday, September 20, 2014 12:43 AM