Menu

problem in adding the child table data

Maya
2006-06-30
2013-03-22
  • Maya

    Maya - 2006-06-30

    Hi David,

    I am having three tables Questionnaire with questionnaireID as primaryKey and CountryLanguage table with countryLanguageId as primarykey and CountryLanguageQuestionnaire with composite key(QuestionnaireID and CountryLanguageID)which is having one to many relationship.
    My problem is when i am trying to add the CountryLanguageQuestionnaire object to the Questionnaire object its always giving count of 2 for CountryLanguageQuestionnaire object although i am adding only one CountryLanguageQuestionnaire object to the to the Questionnaire object.
    Can you help me in finding the problem

    Here is the code where i am facing the problem

    DataManager dm = new DataManager(System.Configuration.ConfigurationSettings.AppSettings["dsn"]);
                dm.QueryCriteria.Clear();
                System.Guid statusId=new Guid("DA3F9DAD-6A32-4D78-875C-9F93BFBBECFB");
                System.Guid questionId=new Guid("82EEC64D-1CD4-4A43-9DBE-F01EC5DB0C6B");
                System.Guid CCId=new Guid("DA3F9DAD-6A32-4D78-875C-9F93BFBBECFB");
                System.Guid usageId=new Guid("DA3F9DAD-6A32-4D78-875C-9F93BFBBECFB");

                Questionnaire quest=dm.NewQuestionnaire();            
               
                //assigning the values to the questionnaire
                quest.Title="Test title by Maya on 29/06/2006";
                quest.BusinessImpact="Testing businessImpact";
                quest.BusinessJustification="testing businessjustification";
                quest.CreatedDate=DateTime.Now;
                quest.CreatedBy="Wipro";
                quest.StatusID= statusId;
                quest.UsageTypeID=usageId;
                quest.LastUpdBy="Ike";           

               
                dm.QueryCriteria.Clear(); 
                dm.QueryCriteria.And(JoinPath.CountryLanguage.Columns.CountryCode,"NL",MatchType.Exact);
                CountryLanguage country=dm.GetCountryLanguage();

                CountryLanguageQuestionnaire clq=dm.NewCountryLanguageQuestionnaire();

                //assigning the values to the CountryLanguageQuestionnaire        
                clq.CreatedBy ="wipro";
                clq.CountryLanguageID=country.CountryLanguageID;
               
                //adding the CountryLanguageQuestionnaire object to the Questionnaire object
                quest.AddCountryLanguageQuestionnaire(clq);

    thanks

     
    • David Parslow

      David Parslow - 2006-06-30

      Can you add to your sample code the places where you are checking the count of quest.CountryLanguageQuestionnaires?

      I would also recommend quest.NewCountryLanguageQuestionnaire() instead of dm.NewCountryLanguageQuestionnaire(...) and quest.AddNewCountryLanguageQuestionnaire() as the preferred way to create a child although both techniques should work.

       
      • Maya

        Maya - 2006-07-03

        Hi David,

        When i am taking quest.NewCountryLanguageQuestionnaire() instead of dm.NewCountryLanguageQuestionnaire(...) and quest.AddNewCountryLanguageQuestionnaire() its adding one more count (giving 3 counts).
        And if i am taking dm.NewCountryLanguageQuestionnaire(...) and quest.AddNewCountryLanguageQuestionnaire()its giving me count of 2 although i am adding only one CountryLanguageQuestionnaire object to the Questionnaire object....so the problem is still same.....

        Thanks,
        Maya

         
    • David Parslow

      David Parslow - 2006-07-03

      I have never seen it do anything like that before.  I would use the debugger to step through the code with a watch on quest.CountryLanguageQuestionnaires.Count()

      Also check dm.DataSet.Tables["CountryLanguageQuestionnaire"].Rows to see what rows are getting added (i.e. same row data differing only by auto incremented id, different rows).

      There is also a list changed event that you can subscribe to see list changes.

      Finally, try calling dm.NewCountryLanguageQuestionnaire but do not call quest.AddCountryLanguageQuestionnaire(clq) instead use
      clq.QuestionnaireId = quest.QuestionnaireId (or what ever is you id column name)

      then call dm.CommitAll()
      immediately so you can make sure there the problem is not because of some loop code or that the problem is not elsewhere.

      If you use SQL Server Profiler (a good sql tracing tool) you will be able to see the commits and debug it on a sql level.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.