Question about EditableChild template

Question about EditableChild template

Old forum URL: forums.lhotka.net/forums/t/1790.aspx


wjcomeaux posted on Friday, November 17, 2006

The template generates this code.

#region Factory Methods
 private static int _newID = -1;

 internal static T NewBuildingEC()
 {
  T child = DataPortal.Create<T>();
  child._id = _newID--;
  child.ValidationRules.CheckRules();
  return child;
 }

Where the _newID is created if the object has an Identity field. What is the purpose of the child._id = _newID--? Won't this simply always assign child._id a value of -2 since newID is defaulted to -1? Or am I reading this incorrectly?

Will

rasupit replied on Tuesday, November 21, 2006

Will,
This is c# decrement operator.  Post fix decrement assign the value _before_ it has been decremented.

You can find more detail info on how it works at http://msdn2.microsoft.com/en-us/library/wc3z3k8c.aspx,

HTH,
Ricky

wjcomeaux replied on Tuesday, November 21, 2006

OK, but I was wondering why the negative ID values? Is this simply to keep them unique and also a value that the database would find invalid? Or is there some other reasoning.

P.S. on my other posts, not sure how I missed the XSD file in that directory. :( That would have saved me a LOT of time. :)

Thanks,

Will

Copyright (c) Marimer LLC