no direct support for follwing situation?

Posts   
 
    
exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 05-Jun-2006 18:22:54   

Ok, I have a situation that I do not see a way to retrieve single entity unless I use FetchColleciton and then get entity at index 0 position.

So I have a table that has compound PK

Id - int (PK) Date - datetime (PK)

I cannot use FetchEntity with PK as this will not return me nothing due to conversion (no miliseconds).

So I added another column

RecordId (int, identity) and there is not way to get it by RecordId, I either have to use prefetch paths of FetchCollection?.

I tried making this colum a unique constraint, but since RecordId is marked as readonly (identity filed) then that wont work as I cannot assign value to this property to use adapter.FetchEntityUsingUniqueConstraint

So I have to user either prefetch path or fetchcollection?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 06-Jun-2006 02:36:27   

You should be able to use a predicate expression on the unique constraint to fetch the entity. I don't know the name of your table, but if it was Customer it would look similar to this.

     CustomerEntity customer = new CustomerEntity();
     IPredicateExpression filter = new PredicateExpression();
     filter.Add(CustomerFields.RecordId == 12);
     using (DataAccessAdapter adapter = new DataAccessAdapter())
     {
         adapter.FetchEntityUsingUniqueConstraint(customer, filter);
      }

Let us know how this goes.

exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 06-Jun-2006 15:22:12   

I tried it, but RecordId is readonly since it is Identity field so you cannot assign a value to it.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 07-Jun-2006 02:21:05   

Well using the filter shouldn't try to set the RecordId value. It's just used to find a row with that RecordId. Could you possibly post the code you have and I can see if I can recreate the situation.

exp2000
User
Posts: 68
Joined: 13-Apr-2006
# Posted on: 07-Jun-2006 15:47:25   

sorry, I tried using follwing code. I did not pay attention to your example.

CustomerEntity customer = new CustomerEntity(); customer.RecordId = 12 using (DataAccessAdapter adapter = new DataAccessAdapter()) { adapter.FetchEntityUsingUniqueConstraint(customer,customer.ConstructFilterForUCRecordId); }

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 08-Jun-2006 02:33:53   

Using what I posted should work since it never tries to assign a value to a read-only property.