This is a migrated thread and some comments may be shown as answers.

Reverse Mapped Collection

9 Answers 197 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jeff Morris
Top achievements
Rank 1
Jeff Morris asked on 21 May 2010, 06:14 PM
I have four tables in a  (M:N) relationship,  Infraction, ActionsType, and InfractionxActionType that I have used revesed mapped into a collection.  Here is my scenario, I have two objects, one that is a mapped as a list of the other.  When I add my actiontype object to my infraction I get an error because it is trying to insert a record into the ActionType table instead of the cross reference table.  Below is a sample of my code.  Let me know if there is anything else that is needed to be clearer. 

    public partial class InfractionTempBO : BaseBO  
    {  
 
        private int uIDInfraction; // pk   
 
        public int UIDInfraction  
        {  
            get { return uIDInfraction; }  
            set 
            {  
                if (uIDInfraction != value)  
                {  
                    uIDInfraction = value;  
                    this.IsDirty = true;  
                }  
            }  
        }  
 
        private IList<ActionTypeBO> infractionTempxActionTypes = new List<ActionTypeBO>();  // inverse ActionTypeBO.infractionTemp  
 
        public IList<ActionTypeBO> InfractionTempxActionTypes  
        {  
            get { return infractionTempxActionTypes; }  
            set { infractionTempxActionTypes = value; }  
        }  
 
    public partial class ActionTypeBO : BaseBO  
    {  
        private int uIDActionType; // pk   
 
        public int UIDActionType  
        {  
            get { return uIDActionType; }  
            set { uIDActionType = value; IsDirty = true; }  
        }  
 
        private string actionTypeDescription;  
 
        public string ActionTypeDescription  
        {  
            get { return actionTypeDescription; }  
            set { actionTypeDescription = value; IsDirty = true; }  
        }  
 
        private string actionTypeName;  
 
        public string ActionTypeName  
        {  
            get { return actionTypeName; }  
            set { actionTypeName = value; IsDirty = true; }  
        }  
 
        public ActionTypeBO()  
        {  
        }  
    } 

Here is the reverse mapping portion

            <table name="'InfractionTempxActionType'" type="2" locked="False">  
                <column name="InfractionTempUID" isPk="True" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="False" /> 
                <column name="ActionTypeUID" isPk="True" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="False" /> 
                <column name="CreatedByUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="CreatedDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <column name="ModifiedByUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="ModifiedDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <column name="Stamp" isPk="False" isAutoInc="False" adoType="-5" sqlType="timestamp" length="0" isNull="True" isBackendVersion="True" /> 
                <constraint name="FK_InfractionTempxActionType_ActionType" table="'InfractionTempxActionType'" dest="'ActionType'">  
                    <column name="ActionTypeUID" /> 
                </constraint> 
                <constraint name="FK_InfractionTempxActionType_InfractionTemp" table="'InfractionTempxActionType'" dest="'InfractionTemp'">  
                    <column name="InfractionTempUID" /> 
                </constraint> 
                <field name="infractionTempxActionType" type="4" owner="'InfractionTemp'" reference="'ActionType'">  
                    <mapping field="InfractionTempDA.uIDInfractionTemp (Owner)" column="InfractionTempUID" /> 
                    <mapping field="ActionTypeDA.uIDActionType (Value)" column="ActionTypeUID" /> 
                    <inverse name="infractionTemp" /> 
                </field> 
            </table> 


Thanks

9 Answers, 1 is accepted

Sort by
0
Ady
Telerik team
answered on 25 May 2010, 05:12 PM
Hi Jeff Morris,

 Based on the information you have provided I am not able to ascertain whether the m:n relationship is setup correctly. Can you send me you reversemapping.config file so that I can regenerate the class and the m:n relationship?
 I see that you have introduced a hierarchy in the source code. If that is required to reproduce the problem, maybe you can send me an abridged version of the project where I can reproduce the problem.

Regards,
Ady
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jeff Morris
Top achievements
Rank 1
answered on 25 May 2010, 05:43 PM
I will include more portions of my reversemapping.config file.  I do not want to include my entire file because it is quite large.  Are there other sections that you are looking for specificially?  My project is set up very similar to the N-Tier example given in your code bank.  The basic flow is that I have a Business object that mirrors what is generated from OpenAccess.  Then I have an assembler class that converts between the two. 

Here is more from my reversemapping.config file.
 
            <table name="'ActionType'" type="1" locked="False">  
                <column name="UIDActionType" isPk="True" isAutoInc="True" adoType="4" sqlType="int" length="0" isNull="False" /> 
                <column name="ActionTypeName" isPk="False" isAutoInc="False" adoType="12" sqlType="varchar" length="50" isNull="False" /> 
                <column name="ActionTypeDescription" isPk="False" isAutoInc="False" adoType="12" sqlType="varchar" length="255" isNull="True" /> 
                <column name="CreatedByUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="CreatedDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <column name="ModifiedByUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="ModifiedDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <column name="Stamp" isPk="False" isAutoInc="False" adoType="-5" sqlType="timestamp" length="0" isNull="True" isBackendVersion="True" /> 
                <index name="IX_ActionType" unique="True" clustered="False">  
                    <column name="ActionTypeName" /> 
                </index> 
                <class name="ActionTypeDA" check="-1" generated="True">  
                    <field name="uIDActionType" type="1" isPK="True" isAutoInc="True" column="UIDActionType" valueType="System.Int32" /> 
                    <field name="actionTypeDescription" type="1" isPK="False" column="ActionTypeDescription" valueType="System.String" /> 
                    <field name="actionTypeName" type="1" isPK="False" column="ActionTypeName" valueType="System.String" /> 
                    <field name="createdByUID" type="1" isPK="False" column="CreatedByUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="createdDate" type="1" isPK="False" column="CreatedDate" valueType="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="modifiedByUID" type="1" isPK="False" column="ModifiedByUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="modifiedDate" type="1" isPK="False" column="ModifiedDate" valueType="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="stamp" type="1" isPK="False" isVersion="True" column="Stamp" valueType="System.Int64" /> 
                </class> 
            </table> 
 
            <table name="'InfractionTempxActionType'" type="2" locked="False">  
                <column name="InfractionTempUID" isPk="True" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="False" /> 
                <column name="ActionTypeUID" isPk="True" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="False" /> 
                <column name="CreatedByUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="CreatedDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <column name="ModifiedByUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="ModifiedDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <column name="Stamp" isPk="False" isAutoInc="False" adoType="-5" sqlType="timestamp" length="0" isNull="True" isBackendVersion="True" /> 
                <constraint name="FK_InfractionTempxActionType_ActionType" table="'InfractionTempxActionType'" dest="'ActionType'">  
                    <column name="ActionTypeUID" /> 
                </constraint> 
                <constraint name="FK_InfractionTempxActionType_InfractionTemp" table="'InfractionTempxActionType'" dest="'InfractionTemp'">  
                    <column name="InfractionTempUID" /> 
                </constraint> 
                <field name="infractionTempxActionType" type="4" owner="'InfractionTemp'" reference="'ActionType'">  
                    <mapping field="InfractionTempDA.uIDInfractionTemp (Owner)" column="InfractionTempUID" /> 
                    <mapping field="ActionTypeDA.uIDActionType (Value)" column="ActionTypeUID" /> 
                    <inverse name="infractionTemp" /> 
                </field> 
            </table> 
 
            <table name="'InfractionTemp'" type="1" locked="False">  
                <column name="StudentUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="SchoolUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="InfractionEventUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="InfractionLocationUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="ReferredByUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="ReportCompletedByUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="ConferenceTypeUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="InfractionStatusUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="SuspensionTypeUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="WeaponUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="RecommendedAction" isPk="False" isAutoInc="False" adoType="12" sqlType="varchar" length="255" isNull="True" /> 
                <column name="InfractionDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <column name="OtherLocation" isPk="False" isAutoInc="False" adoType="12" sqlType="varchar" length="255" isNull="True" /> 
                <column name="HearingDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <column name="HomeworkAssigned" isPk="False" isAutoInc="False" adoType="-1" sqlType="varchar(max)" length="0" isNull="True" /> 
                <column name="AccidentReportCompleted" isPk="False" isAutoInc="False" adoType="-7" sqlType="bit" length="0" isNull="True" /> 
                <column name="GangRelated" isPk="False" isAutoInc="False" adoType="-7" sqlType="bit" length="0" isNull="True" /> 
                <column name="SuspensionStartDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <column name="SuspensionReturnDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <column name="SuspensionDays" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="OtherParticipants" isPk="False" isAutoInc="False" adoType="12" sqlType="varchar" length="255" isNull="True" /> 
                <column name="IncidentNarrative" isPk="False" isAutoInc="False" adoType="-1" sqlType="varchar(max)" length="0" isNull="True" /> 
                <column name="IncidentNotes" isPk="False" isAutoInc="False" adoType="-1" sqlType="varchar(max)" length="0" isNull="True" /> 
                <column name="IncidentReportNo" isPk="False" isAutoInc="False" adoType="12" sqlType="varchar" length="50" isNull="True" /> 
                <column name="PoliceRDNumber" isPk="False" isAutoInc="False" adoType="12" sqlType="varchar" length="50" isNull="True" /> 
                <column name="Conclusion" isPk="False" isAutoInc="False" adoType="-1" sqlType="varchar(max)" length="0" isNull="True" /> 
                <column name="CreatedByUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="CreatedDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <column name="ModifiedByUID" isPk="False" isAutoInc="False" adoType="4" sqlType="int" length="0" isNull="True" /> 
                <column name="ModifiedDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <column name="Stamp" isPk="False" isAutoInc="False" adoType="-5" sqlType="timestamp" length="0" isNull="True" isBackendVersion="True" /> 
                <column name="UIDInfractionTemp" isPk="True" isAutoInc="True" adoType="4" sqlType="int" length="0" isNull="False" /> 
                <column name="ParentConferenceDate" isPk="False" isAutoInc="False" adoType="93" sqlType="datetime" length="0" isNull="True" /> 
                <class name="InfractionTempDA" check="-1" generated="True">  
                    <field name="uIDInfractionTemp" type="1" isPK="True" isAutoInc="True" column="UIDInfractionTemp" valueType="System.Int32" /> 
                    <field name="accidentReportCompleted" type="1" isPK="False" column="AccidentReportCompleted" valueType="System.Nullable`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="conclusion" type="1" isPK="False" column="Conclusion" valueType="System.String" /> 
                    <field name="conferenceTypeUID" type="1" isPK="False" column="ConferenceTypeUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="createdByUID" type="1" isPK="False" column="CreatedByUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="createdDate" type="1" isPK="False" column="CreatedDate" valueType="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="gangRelated" type="1" isPK="False" column="GangRelated" valueType="System.Nullable`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="hearingDate" type="1" isPK="False" column="HearingDate" valueType="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="homeworkAssigned" type="1" isPK="False" column="HomeworkAssigned" valueType="System.String" /> 
                    <field name="incidentNarrative" type="1" isPK="False" column="IncidentNarrative" valueType="System.String" /> 
                    <field name="incidentNotes" type="1" isPK="False" column="IncidentNotes" valueType="System.String" /> 
                    <field name="incidentReportNo" type="1" isPK="False" column="IncidentReportNo" valueType="System.String" /> 
                    <field name="infractionDate" type="1" isPK="False" column="InfractionDate" valueType="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="infractionEventUID" type="1" isPK="False" column="InfractionEventUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="infractionLocationUID" type="1" isPK="False" column="InfractionLocationUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="infractionStatusUID" type="1" isPK="False" column="InfractionStatusUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="modifiedByUID" type="1" isPK="False" column="ModifiedByUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="modifiedDate" type="1" isPK="False" column="ModifiedDate" valueType="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="otherLocation" type="1" isPK="False" column="OtherLocation" valueType="System.String" /> 
                    <field name="otherParticipants" type="1" isPK="False" column="OtherParticipants" valueType="System.String" /> 
                    <field name="parentConferenceDate" type="1" isPK="False" column="ParentConferenceDate" valueType="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="policeRDNumber" type="1" isPK="False" column="PoliceRDNumber" valueType="System.String" /> 
                    <field name="recommendedAction" type="1" isPK="False" column="RecommendedAction" valueType="System.String" /> 
                    <field name="referredByUID" type="1" isPK="False" column="ReferredByUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="reportCompletedByUID" type="1" isPK="False" column="ReportCompletedByUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="schoolUID" type="1" isPK="False" column="SchoolUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="studentUID" type="1" isPK="False" column="StudentUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="suspensionDays" type="1" isPK="False" column="SuspensionDays" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="suspensionReturnDate" type="1" isPK="False" column="SuspensionReturnDate" valueType="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="suspensionStartDate" type="1" isPK="False" column="SuspensionStartDate" valueType="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="suspensionTypeUID" type="1" isPK="False" column="SuspensionTypeUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="weaponUID" type="1" isPK="False" column="WeaponUID" valueType="System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" /> 
                    <field name="stamp" type="1" isPK="False" isVersion="True" column="Stamp" valueType="System.Int64" /> 
                    <field name="infractionEvent" type="2" isPK="False" reference="'InfractionEvent'">  
                        <mapping field="InfractionEventDA.uIDInfractionEvent" column="InfractionEventUID" /> 
                        <inverse name="infractionTemp" /> 
                    </field> 
                </class> 
            </table> 

Here is an excerpt from the generated files. 
    public partial class InfractionTempDA   
    {  
        private int uIDInfractionTemp; // pk   
 
        private bool? accidentReportCompleted;  
 
        private string conclusion;  
 
        private int? conferenceTypeUID;  
 
        private int? createdByUID;  
 
        private DateTime? createdDate;  
 
        private bool? gangRelated;  
 
        private DateTime? hearingDate;  
 
        private string homeworkAssigned;  
 
        private string incidentNarrative;  
 
        private string incidentNotes;  
 
        private string incidentReportNo;  
 
        private DateTime? infractionDate;  
 
        private int? infractionEventUID;  
 
        private int? infractionLocationUID;  
 
        private int? infractionStatusUID;  
 
        private int? modifiedByUID;  
 
        private DateTime? modifiedDate;  
 
        private string otherLocation;  
 
        private string otherParticipants;  
 
        private DateTime? parentConferenceDate;  
 
        private string policeRDNumber;  
 
        private string recommendedAction;  
 
        private int? referredByUID;  
 
        private int? reportCompletedByUID;  
 
        private int? schoolUID;  
 
        private int? studentUID;  
 
        private int? suspensionDays;  
 
        private DateTime? suspensionReturnDate;  
 
        private DateTime? suspensionStartDate;  
 
        private int? suspensionTypeUID;  
 
        private int? weaponUID;  
 
        private InfractionEventDA infractionEvent; // inverse InfractionEventDA.infractionTemp  
 
        private IList<InfractionTempxInfractionCodexInfractionSeverityDA> infractionTempxInfractionCodexInfractionSeverity = new List<InfractionTempxInfractionCodexInfractionSeverityDA>();  // inverse InfractionTempxInfractionCodexInfractionSeverityDA.infractionTemp  
 
        private IList<InfractionTempxStudentRoleDA> infractionTempxStudentRole = new List<InfractionTempxStudentRoleDA>();  // inverse InfractionTempxStudentRoleDA.infractionTemp  
 
        private IList<ActionTypeDA> infractionTempxActionType = new List<ActionTypeDA>();  // inverse ActionTypeDA.infractionTemp  
 
        private IList<InfractionFactorDA> infractionTempxInfractionFactor = new List<InfractionFactorDA>();  // inverse InfractionFactorDA.infractionTemp  
 
 
        public InfractionTempDA()   
        {  
        }  

Here is an excerpt from how I am adding the action types

            InfractionTempDA savedInfraction;  
            if (boInfraction.UIDInfraction > 0)  
                savedInfraction = (InfractionTempDA)scope.GetObjectById(Database.OID.ParseObjectId(typeof(InfractionTempDA), boInfraction.UIDInfraction.ToString()));  
            else 
                savedInfraction = new InfractionTempDA();  
            savedInfraction = InfractionTempDisassembler.DisassembleContract(ref savedInfraction, boInfraction);  
 
            List<ActionTypeDA> daActionType = ActionTypeDisassembler.DisassembleContracts(boInfraction.InfractionTempxActionTypes);  
 
            foreach (ActionTypeDA da in daActionType )  
            {  
                scope.Transaction.Begin();  
                savedInfraction.InfractionTempxActionTypes.Add(da);  
                scope.Transaction.Commit();  
            } 
0
Ady
Telerik team
answered on 26 May 2010, 02:38 PM
Hello Jeff Morris,

 I did generate the classes from the mapping you provided and could successfully add an ActionTypeDA instance to the InfractionTempDA.InfractionTempxActionTypes field.
The m:n mapping is fine. Can you send me the call stack of the exception that you get? That will help in further analyzing the problem.

Regards,
Ady
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jeff Morris
Top achievements
Rank 1
answered on 26 May 2010, 03:53 PM
Below is the error that I received.  The error is caused by a unique constraint that I have on the action type table.  It is acting like it is trying to insert a new record into the actiontype table that already exists instead of adding the record to the cross reference table.  This happens on the commit of the transaction in the code below

Insert of '924102936-1' failed: Telerik.OpenAccess.RT.sql.SQLException: Violation of UNIQUE KEY constraint 'IX_ActionType'. Cannot insert duplicate key in object 'dbo.ActionType'.  
The statement has been terminated.  
   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()  
   at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()  
   at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)  
INSERT INTO [ActionType] ([ActionTypeDescription], [ActionTypeName], [CreatedByUID], [CreatedDate], [ModifiedByUID], [ModifiedDate]) VALUES (?, ?, ?, ?, ?, ?)  
select scope_identity()  
(set event logging to all to see parameter values) 

            foreach (ActionTypeDA da in addActionType)  
            {  
                scope.Transaction.Begin();  
                savedInfraction.InfractionTempxActionTypes.Add(da);  
                scope.Transaction.Commit();  
            } 


Thank you.

0
Ady
Telerik team
answered on 28 May 2010, 01:42 PM
Hello Jeff Morris,

It seems that the unique index 'IX_ActionType' on the 'ActionTypeName' column is voilated. Maybe a unique value is not provided everytime you add a new instance of 'ActionTypeDA'.
Can you please verify that?

Sincerely yours,
Ady
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jeff Morris
Top achievements
Rank 1
answered on 02 Jun 2010, 04:58 PM
I finally got it to work.  It appears that I need to make another call to the database to pull the correct action type object.  In my disassembler method in the line
List<ActionTypeDA> daActionType = ActionTypeDisassembler.DisassembleContracts(boInfraction.InfractionTempxActionTypes);   

Event thouch each item in my daActionType existed with the correct UID.  I needed to make another call.  My final method looks like something below.  If you have any suggestions on how/why i need this extra call or know of a way that I can avoid making this call I would appreciate it, but this is working.  


            foreach (ActionTypeDA da in addActionType) 
            { 
                ActionTypeDA daTemp = (ActionTypeDA)scope.GetObjectById(Database.OID.ParseObjectId(typeof(ActionTypeDA), da.UIDActionType.ToString())); 
                scope.Transaction.Begin(); 
                savedInfraction.InfractionTempxActionTypes.Add(daTemp); 
                scope.Transaction.Commit(); 
            } 


0
Ady
Telerik team
answered on 04 Jun 2010, 11:46 AM
Hi Jeff Morris,

 If the 'ActionTypeDisassembler.DisassembleContracts' method obtains the 'List<ActionTypeDA>' using the same scope you shouldn't need to ask for the object again.It seems that instances obtained via 'DisassembleContracts' are somehow not associated to the scope.
Can you send me a small sample where I can reproduce this behavior or some more details on how the 'List<ActionTypeDA>' is obtained?

Sincerely yours,
Ady
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jeff Morris
Top achievements
Rank 1
answered on 04 Jun 2010, 03:57 PM
Below is a snippet of my disassemble contract methods.  I created these functions to serve the reverse functionality of the assembler.  Since the Assembler takes a persistent object and transforms it into the corresponding business object for use in the web tier, I wanted to have the disassembler take a business object and transform it into the corresponding persistent object for saving so I can have one consistent place to write this code.  Let me know if there is a better way of doing this.



        internal static List<ActionTypeDA> DisassembleContracts(IEnumerable<ActionTypeBO> froms) 
        { 
            List<ActionTypeDA> tos = new List<ActionTypeDA>(); 
 
            foreach (ActionTypeBO from in froms) 
            { 
                tos.Add(DisassembleContract(from)); 
            } 
 
            return (List<ActionTypeDA>)tos; 
        } 
        internal static ActionTypeDA DisassembleContract(ActionTypeBO from) 
        { 
            ActionTypeDA to = new ActionTypeDA(); 
            to.UIDActionType = from.UIDActionType; 
            to.ActionTypeDescription = from.ActionTypeDescription; 
            to.ActionTypeName = from.ActionTypeName; 
 
            BaseDisassembler.DisassembleContract(from, to); 
            return to; 
        } 

0
Ady
Telerik team
answered on 08 Jun 2010, 09:00 AM
Hi Jeff Morris,

What you are doing is creating a new instance of 'ActionTypeDA' with the same UID and adding that to the collection. For OpenAccess, this is the same as a completely new instance and hence when you commit the transaction a new row insert is attempted,leading to the unique constraint violation.
What you should do is to try and obtain an instance of the same object from the database using its id, as you have rightly done by calling scope.GetObjectById. This loads the right instance and associates it with the current scope. If you now commit the transaction, only the modified properties will be updated.

Do get back in case you have further questions.

Best wishes,
Ady
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
Jeff Morris
Top achievements
Rank 1
Answers by
Ady
Telerik team
Jeff Morris
Top achievements
Rank 1
Share this question
or