Adding entity copies to EntityCollection

Posts   
 
    
mattsmith321 avatar
Posts: 146
Joined: 04-Oct-2004
# Posted on: 02-Apr-2005 08:05:25   

Hi everyone!

I have the following code:


EntityCollection eventInstances = new EntityCollection(new EventEntityFactory());
...
foreach (DateTime dt in dc) 
{
    EventEntity eventInstance = foundEvent;
    eventInstance.StartDate = dt;
    eventInstances.Add(eventInstance);
}

How can I get the eventInstance that I add to be unique in the eventInstances collection?

I've been around and around with a couple different options. I can either get only 1 instance in the list, or 6 copies of the same event. At first, I assumed EventID had to be unique so I fudged it for a test, but that didn't work. Then I went a couple of iterations with: eventInstances.DoNotPerformAddIfPresent = false; but that didn't work either (got multiples in the list though!). Then I ran across eventInstance.ObjectID and assumed it had to be unique but didn't have any luck there either. Even tried making a new instance with EventEntity(foundEvent.Fields) with no luck.

I'm starting to think that it is coming back to the reference type/value type concept that I had so much fun with not too long ago. If so, how can I get unique events into my collection?

Thanks, Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 02-Apr-2005 11:38:08   

In 1.0.2004.2 I've added uniquing for entity instances, but in 1.0.2004.1 you've to solve it differently. You want unique entity OBJECTS, or you don't want to have the same value twice?

If it's the latter, you could use a hashtable to which you add as key the value you want to have uniquely in the collection. Then before adding the value, you check if the hashtable contains the key, if not, add it to the collection, if it does, skip.

Frans Bouma | Lead developer LLBLGen Pro
mattsmith321 avatar
Posts: 146
Joined: 04-Oct-2004
# Posted on: 02-Apr-2005 21:22:16   

Otis wrote:

You want unique entity OBJECTS, or you don't want to have the same value twice?

I DO want unique Entity objects in the collection. What I am working with deals with recurring events. Essentially the "foundEvent" is the master event. Each iteration in the foreach is creating an instance of the master event except with a different StartDate.

I've got no problems with trying out your beta of 2004.2 if you think that you have addressed the solution in that code. What would I be looking for codewise to make it happen?

Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 03-Apr-2005 11:26:26   

mattsmith321 wrote:

Otis wrote:

You want unique entity OBJECTS, or you don't want to have the same value twice?

I DO want unique Entity objects in the collection. What I am working with deals with recurring events. Essentially the "foundEvent" is the master event. Each iteration in the foreach is creating an instance of the master event except with a different StartDate.

I've got no problems with trying out your beta of 2004.2 if you think that you have addressed the solution in that code. What would I be looking for codewise to make it happen?

Thanks!

You should use the Context object. Please check the readme.htm file of the beta for a discussion about the Context object. The context object is for unique entity instances simple_smile

Frans Bouma | Lead developer LLBLGen Pro