why is SaveMulti() causing new entities to be created?

Posts   
 
    
nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 06-May-2008 03:19:34   

I thought i would put this out here as i am getting nowhere with this problem.

I have the following entities: Evidence, Question, QuestionGroup.

They are related and assigned to each other thru these other entities: EvidenceQuestion, EvidenceQuestionGroupAssignment.

I have been creating an collection of MyEvidenceQuestionGroupAssignments, giving them one intsance of the evidence and several of the question and question groups for each assignment and calling the SaveMulti(True) to recurse thru the collection and save all related entities.

The problem is that for some reason i have been getting an extra new and empty evidence entity inserted into the database.

any ideas on where to lok for this extra entity? it must have been instantiated somewhere during the processes af assignment above (perhaps when New Question() or New QuestionGroup() are called?) -- otherwise it would not be inserting into the database, right?

nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 06-May-2008 07:14:55   

okay i think i figured out the above problem.

now i have a new question....

the Evidence and the Question entities are m:n related thru the EvidenceQuestion entity, which has also a property IsHidden (Boolean).

so if i want to get a list of Questions for an Evidence, i can use the Evidence.GetMultiQuestionCollectionViaEvidenceQuestion() method to retrieve the questions.

But how do i also retrieve whether those questions are hidden, (for example to check a check box and bind the data)?

I guess what i am saying is i am confused on how to deal with properties on the intermedaite entities on m:n realtions in databinding.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-May-2008 09:21:04   

You may use the Designer to create a "field on related field" in the Question entity, to map the isHidden field in the intermediate entity.

And then when fetching use a prefetchPath to the intermediate table.

nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 06-May-2008 15:42:13   

Walaa wrote:

You may use the Designer to create a "field on related field" in the Question entity, to map the isHidden field in the intermediate entity.

And then when fetching use a prefetchPath to the intermediate table.

is there an example of this in the documentation?

i am only able to create fields on related fields when the realtionship is m:1.

again, i am trying to add Questions to Evidence (which is a m:n: realtionship through the intermediate EvidenceQuestion entity).

since Evidence to EvidenceQuestion is 1:n and Question to EvidenceQuestion is 1:n as well, the only m:1 realtionship are EvidenceQuestion to Evidence and EvidenceQuestion to Question.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-May-2008 15:53:12   

You are right. flushed

If you need the IsHidden field for databinding, you can just access a related fetched (prefetched) entity in databinding.

Also it's better to use a DynamicList or a TypedList to fetch fields from more than one entity in a flat read-only way.

nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 06-May-2008 17:13:09   

Walaa wrote:

If you need the IsHidden field for databinding, you can just access a related fetched (prefetched) entity in databinding.

okay, thats what i was trying to do... but i just would like to confirm that the correct approach to associating Questions to Evidence is the following: instantiate collections of Questions, bind them to a list or grid (where i may select them), and then in my code behind iterate thru the list of Questions to create EvidenceQuestion entities (my intermediate entity) to add to the Evidence.EvidenceQuestions collection. Then i can add an IsHidden check box (not bound to the data) and set that property of the EvidenceQuestion on save.

The problem with this approach is that i would also like to be able to retrieve the Questions currently associated with an Evidence and bind their EvidenceQuestion.IsHidden property to a check box, then use this list as a starting point for modification of the curent Evidence.EvidenceQuestions collection.

This leads to the other approach i can think of, which would be to instantiate a list of EvidenceQuestions (belonging to the Evidence), and then save any changes to them and add any new ones based on availabel Questions.

Which is the pattern you guys would recommend?

(thanks for your helpful replies, by the way!)

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 06-May-2008 18:16:02   

bind them to a list or grid (where i may select them)

You lost me here.

As Walla pointed out before, you can always retrieve the desired dataset via typedlist or dynamiclist and then modify what you need manually through some event in your form (i.e. not int the typed/dynamic list due this ones are readonly, but directly to the entities involved), this for me would be the more practical approach.