Don't use PrimaryKeyType.Increment. This ID generator counts only locally, thus creating always 1 if you don't use a SessionScope. However, PrimaryKeyType.Increment is always an invitation to disaster. Omit the primary key type to use SQL Server's IDENTITY feature. You might also use a GUID PK instead, then using PrimaryKeyType.GuidComb.
-Markus 2009/10/15 Eduard Kruger <[email protected]> > > Hi all, > > I have these 2 classes in a C# 3.5 WCSF Web Application > > > [ > > > > ActiveRecord(Lazy=true)][Serializable > ] > > > > > > > public class Class1: AuditableBase, > iClass1 > > { > > [ > > > > PrimaryKey(Generator = PrimaryKeyType > .Increment)] > > > > > > > public virtual int Id { get; set > ; } > > [ > > > > > Property > ] > > > > > > > public virtual string Name { get; set > ; } > > [ > > > > > BelongsTo("QuestionnaireProfileVersionId", Type = typeof > (QuestionnaireProfileVersion), Cascade = CascadeEnum > .All)] > > > > > > > public virtual iQuestionnaireProfileVersion QuestionnaireProfile > { get; set > ; } > > [ > > > > > Property > ] > > > > > > > public virtual TimeSpan TimeLimit { get; set > ; } > > [ > > > > > Property > ] > > > > > > > public virtual bool isChangeLimited { get; set > ; } > > [ > > > > > Property > ] > > > > > > > public virtual int RemainingChanges { get; set > ; } > > [ > > > > > Property > ] > > > > > > > public virtual bool LimitInternetUserOnly { get; set > ; } > > [ > > > > > Property(ColumnType = "BinaryBlob", SqlType="varbinary(max)" > )] > > > > > > > public virtual byte[] BannerImage { get; set > ; } > > [ > > > > > Property > ] > > > > > > > public virtual string BannerImageType { get; set > ; } > > [ > > > > > Property > ] > > > > > > > public virtual string TermsConditions { get; set > ; } > > [ > > > > > HasMany(typeof(User), Cascade = ManyRelationCascadeEnum > .All)] > > > > > > > public virtual IList<iUser> Users { get; set > ; } > > [ > > > > > HasAndBelongsToMany(typeof(Domain), Table = "CedantDomain", ColumnKey > = "CedantId", ColumnRef = "DomainId", Cascade = > ManyRelationCascadeEnum > .All)] > > > > > > > public virtual IList<iDomain> TrustedDomains { get; set > ; } > > [ > > > > > HasMany(typeof(CedantProduct), Cascade = ManyRelationCascadeEnum > .All)] > > > > > > > public virtual IList<iCedantProduct> Products { get; set > ; } > > [ > > > > > HasMany(typeof(CedantMandatoryField), Cascade = > ManyRelationCascadeEnum > .All)] > > > > > > > public virtual IList<iCedantMandatoryField> MandatoryField { get; set > ; } > > [ > > > > > HasAndBelongsToMany(typeof(Class2), Table = "Table3", ColumnKey = > "Class1Id", ColumnRef = "Class2Id", Cascade = ManyRelationCascadeEnum > .All)] > > > > > > > public virtual IList<IClass2> Class2Items { get; set > ; } > > The Outcome Group property is the one who is causing the problems, the > OutcomeGroup itself to follow soon: > > > > > > public class Class2: AuditableBase, IClass2 { > > > > > /// <summary> > > > > /// Default class constructor. > > > > /// </summary> > > > > public OutcomeGroup() > > { > > } > > > > [ > > > PrimaryKey(Generator=PrimaryKeyType.Increment)] > > > > > public virtual int Id{get;set;} > > [ > > > Property(Unique=true, Index="idx_uq_OutcomeGroupId")] > > > > > public virtual string OutcomeGroupUniqueId > > { > > > > > get; > > > > > set; > > } > > [ > > > Property()] > > > > > public virtual string OutcomeGroupName > > { > > > > > get; > > > > > set; > > } > > [ > > > HasMany(typeof(OutcomeGroupOutcome), Cascade = > ManyRelationCascadeEnum.AllDeleteOrphan)] > > > > > public virtual IList<IOutcomeGroupOutcome> OutcomeGroupOutcomes > > { > > > > > get; > > > > > set; > > } > > [ > > > HasAndBelongsToMany(typeof(Class1), Table = "Table2", ColumnKey = > "Class2Id", ColumnRef = "Class1Id", Cascade = > ManyRelationCascadeEnum.All)] > > > > > public virtual IList<iClass1> Class1Items > > { > > > > > get; > > > > > set; > > } > > > } > > I am trying to add a combo of these 2 classes together for the Class1 > Items and Class 2 Items many-to-many link, which works fine for the > first time you try to save something, however any time thereafter if > you try to save something, the following exception is thrown: > a different object with the same identifier value was already > associated with the session: 1, of entity: Class1 > > It almost seems as if the system is trying to save the original record > (Class1) again in the database using the same ID, however no SQL is > executed (I checked with Profiler, nothing gets fired). > > What am I missing or doing wrong? This is my First time working with > ActiveRecord and have exhausted all means of trying to repair it. > > Any help would be greatly appreciated.... > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
