String representations for Entity properties of type Time With Time Zone, Period and Year/Month Intervals that are mapped to System.String may be either the "L" or "G" format. However, property changes in the object context are tracked in the cache and not overwritten with values from the database after a call to SaveChanges() unless the Refresh method is called on the ObjectContext. Therefore, programmers should use the "G" format (not the "L" format) when updating Entity properties of type Time With Time Zone, Period and Year/Month Intervals.
Here is example code to show the entity cached values for the two format vs. the database values:
Example |
Copy Code |
---|---|
PeriodEntities context = new PeriodEntities (); where p.ID == 1 select p; var result = query.First(); // use "L" format PeriodDate lEntity = new PeriodDate(); lEntity.ID = 1; lEntity.PeriodDateCol = "(date '1937-09-05', date '1976-11-27')"; // Send the changes to the SQL Engine. context.SaveChanges(); // compare Console.WriteLine(lEntity.PeriodDateCol == result.PeriodDateCol); // use "G" format PeriodDate gEntity = new PeriodDate (); gEntity.ID = 2; gEntity.PeriodDateCol = "(1937-09-05, 1976-11-27)"; // Send the changes to the SQL Engine. context.SaveChanges(); // compare Console.WriteLine(gEntity.PeriodDateCol == result.PeriodDateCol); |
In summary, if the "L" format is used as the string representations for Time With Time Zone, Period and Year/Month Intervals type properties, the string values in the entity object may not match the values from the database.
See the following topics for more details on formatting strings for: