Polymorphic FetchEntityUsingUniqueConstraint

Posts   
 
    
garrett
User
Posts: 33
Joined: 21-Feb-2008
# Posted on: 08-Jul-2010 13:36:38   

Just wondering if there's any way to load an entity via a unique constraint when the unique constraint in on an abstract base type in an inheritance chain and you're unsure which subclass the unique value will load up.

The docs have:


DataAccessAdapter adapter = new DataAccessAdapter();
CustomerEntity customer = new CustomerEntity();
customer.CompanyName = "Chop-suey Chinese";
adapter.FetchEntityUsingUniqueConstraint(customer, customer.ConstructFilterForUCCompanyName());


Line 2 obviously isn't possible though when the entity is abstract so you end up having to do something like.


DataAccessAdapter adapter = new DataAccessAdapter();
CustomerEntity customer = (CustomerEntity)adapter.FetchNewEntity(new CustomerEntityFactory(), new RelationPredicateBucket(CustomerFields.CompanyName == "Chop-suey Chinese"));


This just instantiates a CustomerEntity even when the database row doesn't exist. Which is kind of weird given the entity is marked as abstract in the designer. Any thoughts?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 08-Jul-2010 22:56:39   
garrett
User
Posts: 33
Joined: 21-Feb-2008
# Posted on: 09-Jul-2010 01:10:00   

MTrinder wrote:

Can you use the FetchPolymorphic methods...?

http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/SelfServicing/gencode_usingentityclasses.htm#Polymorphicfetches

Matt

Thanks Matt

But I think that method is only available on SelfServicing. I'm using Adapter on LLBL 3.0

Cheers Anyways Garrett

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-Jul-2010 08:52:26   
garrett
User
Posts: 33
Joined: 21-Feb-2008
# Posted on: 09-Jul-2010 09:15:24   

Walaa wrote:

Here you are: Polymorphic fetches (Adapter v.3.0)

Hi Walaa

Thats as I was saying above but the docs only deals with polymorphic fetching relations. Also, I was saying, that call returns a new instance of the abstract base when there is no matching concrete instance in the database.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-Jul-2010 09:54:20   

FetchNewEntity() should be polymorphic. So the returned customer would be of the correct type, if found in the database. If not the method will return a new instnace of CustomerEntity.

You can check on IsNew property of the returned entity, to check if it was fetched from the database or not.

garrett
User
Posts: 33
Joined: 21-Feb-2008
# Posted on: 10-Jul-2010 11:52:40   

Yeah Thanks Walaa

I figured that much out but was just wondering how / why / if i was missing something since FetchNewEntity is returning an instance of an "abstract" class

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-Jul-2010 02:12:06   

I don't understand whether or not your questions have been answered or whether we should elaborate more...

David Elizondo | LLBLGen Support Team
garrett
User
Posts: 33
Joined: 21-Feb-2008
# Posted on: 12-Jul-2010 09:47:44   

daelmo wrote:

I don't understand whether or not your questions have been answered or whether we should elaborate more...

I think it's more or less answered daelmo. I wanted to know if there was a better way of loading stuff polymorphically but it seems not. I guess my other question is not really important but just points out that its a little confusing to get back an instance of a class which is supposed to be abstract.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Jul-2010 13:27:16   

If you look at the class file, you won't find the abstract keyword next to the class.

The class' constructor is internal. This means that you can't create an instance yourself, but the generated code can internally create instances.