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
//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";
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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.
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
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.