Type converter is ignored when fetching entity with ExcludeIncludeFieldsList

Posts   
 
    
Barry
User
Posts: 232
Joined: 17-Aug-2005
# Posted on: 22-Aug-2007 05:43:14   

I'm trying the new features in v2.5 (2.5.7.820), and I found a problem when fetching entity with ExcludeIncludeFieldsList.

I've an entity, which contains a boolean field (database type is nvarchar) and it has a type converter assigned to convert a string (Y/N) to a boolean value.

When I fetch an entity with ExcludeIncludeFieldsList, the current value of the boolean field is a string instead of boolean, and it throw an InvalidCastException when I access the field value.


ExcludeIncludeFieldsList fieldList = new ExcludeIncludeFieldsList(false);
fieldList.Add(ItemFields.Suspended);
adapter.FetchEntity(item, null, null, fieldList);
bool isSuspended = item.Suspended // InvalidCastException occur

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 22-Aug-2007 10:01:51   

Bug. I'll fix it today.

(edit): looking at your code again it doesn't make sense: excluded fields are simply filtered out the list of fields to fetch, it then follows the same fetch routine as every entity fetch does. The fetching of excluded fields AFTERWARDS needs checking if a type converter indeed is used or not. I'll see if I can reproduce this, but it looks odd. Could you double double check that the fetch without excluded fields works OK?

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 22-Aug-2007 11:50:45   

Reproduced. Looking into it.

It's a bug in the routine which reads the values into the fields list. It uses the column ordinal index to check whether the persistence info is there, but that's not correct. Will release a fix later today.

(edit) This bug is fixed in the next build. Related to this: fetching the excluded fields into an existing entity again, and the field has a type converter, this too fails and this too will be fixed in the next build released later today. Sorry for this oversight.

Frans Bouma | Lead developer LLBLGen Pro
Barry
User
Posts: 232
Joined: 17-Aug-2005
# Posted on: 22-Aug-2007 14:04:58   

Thank you simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 22-Aug-2007 18:46:34   

It's available simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Barry
User
Posts: 232
Joined: 17-Aug-2005
# Posted on: 31-Aug-2007 06:18:19   

I'm using using v2.5.7.827, I found this problem existed in FetchEntityCollection() too, please check it. Thank you very much!!!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 31-Aug-2007 11:00:50   

Barry wrote:

I'm using using v2.5.7.827, I found this problem existed in FetchEntityCollection() too, please check it. Thank you very much!!!

Hmm, weird, as the bug was in the routine used by all fetch routines. I did fix it with FetchEntityCollection as well, at least added the necessary code there. You still see this behavior popping up with FetchEntityCollection? I'll check if I pass the correct indexes...

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 31-Aug-2007 14:29:43   

Can't reproduce it. This test should fail if the bug was still there in the first fetch:


[Test]
public void TypeConverterWithExcludedFieldsInCollectionTest()
{
    using(DataAccessAdapter adapter = new DataAccessAdapter())
    {
        EntityCollection toDelete = new EntityCollection();

        FamilyCarEntity companyCar1 = new FamilyCarEntity();
        companyCar1.CarId = 1;
        companyCar1.Brand = "Fiat";
        companyCar1.HasDrawHook = true;
        companyCar1.Price = 10000M;

        toDelete.Add(companyCar1);

        Assert.IsTrue(adapter.SaveEntity(companyCar1));

        // fetch only the HasDrawHook field.
        ExcludeIncludeFieldsList excludedFields = new ExcludeIncludeFieldsList(false);
        excludedFields.Add(FamilyCarFields.HasDrawHook);
        EntityCollection<FamilyCarEntity> familyCars = new EntityCollection<FamilyCarEntity>();
        adapter.FetchEntityCollection(familyCars, excludedFields, null);
        Assert.AreEqual(1, familyCars.Count);
        Assert.IsTrue(familyCars[0].HasDrawHook.Value);

        // fetch the entity again, but now with the drawhook field excluded.
        familyCars.Clear();
        excludedFields.ExcludeContainedFields = true;
        adapter.FetchEntityCollection(familyCars, excludedFields, null);
        Assert.AreEqual(1, familyCars.Count);
        Assert.IsFalse(familyCars[0].HasDrawHook.HasValue);
        Assert.IsNull(familyCars[0].HasDrawHook);

        // now fetch the field 
        adapter.FetchExcludedFields(familyCars, excludedFields);
        Assert.IsTrue(familyCars[0].HasDrawHook.Value);

        adapter.DeleteEntityCollection(toDelete);
    }
}

as the hasdrawhook field is at the end of the entity and excluding everything else would cause the bug to pop up, but the field is correctly read.

(test on oracle with type converter on hasdrawhook field. Database type has no effect on this)

Frans Bouma | Lead developer LLBLGen Pro
kbeaudoin
User
Posts: 8
Joined: 01-May-2007
# Posted on: 05-Nov-2007 15:19:59   

Seems to have the same problem using version 2.5.7.1019. Receive invalid cast exception on fields that should be managed by converters when I use the FetchEntityCollection while specifying an ExcludeIncludeFieldsList.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 05-Nov-2007 15:28:34   

kbeaudoin wrote:

Seems to have the same problem using version 2.5.7.1019. Receive invalid cast exception on fields that should be managed by converters when I use the FetchEntityCollection while specifying an ExcludeIncludeFieldsList.

Please next time open a new thread.

Could you provide more info? - code, db schema, which fields you have the converters on, which fields were excluded, was there inheritance in use? which database type? etc.

Frans Bouma | Lead developer LLBLGen Pro
kbeaudoin
User
Posts: 8
Joined: 01-May-2007
# Posted on: 05-Nov-2007 16:03:13   

Sorry for the new Message next time i'll open a new thread. flushed

Found a solution to my problem, but not quite sure why it was causing a problem only when I was using the FetchEntityCollection where you can specify a FieldExclusionList.

In the designer we had a Decimal field that was converted to a System.Single, but no converters where set (Both Set and Reset to Default were enabled in designer). Maybe there were really a converter set in the past when we were using a previous version of LLBL. This entity is mapped on a view and our LLBL project was updated from 1.0 to 2.0 and finally 2.5. Maybe this was caused by one of our migration or during a refresh schema, I can't really tell. Anyway after I removed the conversion using the reset to default button, everything is working... But don't know why it was working with a classic FetchEntityColleciton and wasn't when I specified a FieldExclusionList.

So everything is fine after all.