public long GetNextSequence(XPClassInfo classInfo) { if (classInfo == null) throw new ArgumentNullException("classInfo"); XPClassInfo ci = classInfo; //Dennis: Uncomment this code if you want to have the SequentialNumber column created in each derived class table. while (ci.BaseClass != null && ci.BaseClass.IsPersistent) { ci = ci.BaseClass; } _seq = euow.GetObjectByKey<Sequence>(ci.FullName, true); if (_seq == null) { throw new InvalidOperationException(string.Format("Sequence for the {0} type was not found.", ci.FullName)); } long nextSequence = _seq.NextSequence; _seq.NextSequence++; euow.FlushChanges(); return nextSequence; }
//Dennis: It is necessary to generate (only once) sequences for all the persistent types before using the GetNextSequence method. public static void RegisterSequences(IEnumerable<ITypeInfo> persistentTypes) { if (persistentTypes != null) using (var uow = new UnitOfWork(DefaultDataLayer)) { var sequenceList = new XPCollection<Sequence>(uow); var typeToExistsMap = new Dictionary<string, bool>(); foreach (Sequence seq in sequenceList) { typeToExistsMap[seq.TypeName] = true; } foreach (ITypeInfo typeInfo in persistentTypes) { ITypeInfo ti = typeInfo; if (typeToExistsMap.ContainsKey(ti.FullName)) continue; //Dennis: Uncomment this code if you want to have the SequentialNumber column created in each derived class table. while (ti.Base != null && ti.Base.IsPersistent) { ti = ti.Base; } string typeName = ti.FullName; //Dennis: This code is required for the Domain Components only. if (ti.IsInterface && ti.IsPersistent) { Type generatedEntityType = XpoTypesInfoHelper.GetXpoTypeInfoSource().GetGeneratedEntityType(ti.Type); if (generatedEntityType != null) typeName = generatedEntityType.FullName; } if (typeToExistsMap.ContainsKey(typeName)) continue; if (ti.IsPersistent) { typeToExistsMap[typeName] = true; var seq = new Sequence(uow); seq.TypeName = typeName; seq.NextSequence = 0; } } uow.CommitChanges(); } }