EntityView2 empty

Posts   
 
    
Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 17-Jul-2007 14:53:07   

I have 2 views I am creating off of an Organizations Addresses. The main list has all addresses and I need to split them out by way of Physical addresses and Mailing addresses. So, I fetch the entity and create 2 EntityView2 instances using the appropriate predicate expression.

When the form displays the main address datagridview displays all the addresses and the other 2 datagridviews display nothing.

Here is the code for the fetch and view creation:


            organization.OrganizationId = 151;
            DataAccessAdapter adapter = new DataAccessAdapter();
            adapter.FetchEntity(organization);
            physical = new EntityView2<OrganizationAddressEntity>(organization.Address, (OrganizationAddressFields.AddressTypeId == OrganizationAddressEntity.AddressTypePhysical));
            mailing = new EntityView2<OrganizationAddressEntity>(organization.Address, (OrganizationAddressFields.AddressTypeId == OrganizationAddressEntity.AddressTypeMailing));

            addressGrid.DataSource = organization.Address;
            physicalGrid.DataSource = physical;
            mailingGrid.DataSource = mailing;


Just in case, here is the code for OrganizationAddressEntity.AddressTypeMailing and OrganizationAddressTypePhysical:

//  Current values for AddressType
        //  2   Business
        //  1   Mailing
        //  0   Physical

        public static int AddressTypeMailing
        {
            get
            {
                return 1;
            }
        }

        public static int AddressTypePhysical
        {
            get
            {
                return 0;
            }
        }

All 3 datagridviews display the same columns and share a RowsAdded method. Here is the code for it:


private void Grid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            if (sender == null) { return; }
            DataGridView grid = (DataGridView)sender;
            if (grid.DataSource == null) { return; }

            for (int i = e.RowIndex ; i < (e.RowIndex + e.RowCount); i++)
            {
                if (grid.Rows[i].DataBoundItem != null)
                {
                    OrganizationAddressEntity entity = (OrganizationAddressEntity)grid.Rows[i].DataBoundItem;
                    
                    if (entity != null && entity.Address != null)
                    {
                        grid.Rows[i].Cells[0].Value = entity.AddressType.Name;
                        grid.Rows[i].Cells[1].Value = entity.Address.FirstStreetName;
                        grid.Rows[i].Cells[2].Value = entity.Address.CityTown.Name;
                        grid.Rows[i].Cells[3].Value = entity.Address.State.Code;
                        grid.Rows[i].Cells[4].Value = entity.Address.ZipPostalCode.Value;
                    }
                }
            }
        }


What I am seeing is that when the main address grid enters the rowsadded method all is well. When the other 2 enter the method the cast to OrganizationAddressEntity is successful but the all of the child properties, AddressType / Address etc.., are null.

What am I missing??

Thanks.

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 17-Jul-2007 15:18:44   

Hi,

In your code :

DataAccessAdapter adapter = new DataAccessAdapter();
            adapter.FetchEntity(organization);

you don't use a prefetchpath, so the adresses collection is not filled. But you say the main address datagridview displays all the addresses witch should not be possible.

Am I missing something ? what is the count of organization.Address, physical, mailing ?

Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 17-Jul-2007 15:24:46   

My apologies for not noting that the code for the fetch is actually done elsewhere. I am using a prefetch path and I do return all of the values I need to display in the grid. As I mentioned previously, the main list of addresses works correctly and all values are displayed. The problem is with the grids that are bound to the EntityView2 instances.

Thanks.

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 17-Jul-2007 15:57:59   

Hi,

Ok, so it is indeed a really wierd behaviour.

When you debug the rowsAdded method in the 2 datagridview witch don't work, is entity.Address null ? what is the value of entity.Adress.Fields.State ?

Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 17-Jul-2007 16:04:51   

Yes, entity.Address is null. Entity.Address does not have a Field for State, it has a property that is a StateEntity.

Here is some information from the immediate window for entity in the rowsadded method when I come through for the main list of all addresses:


?entity
{Kelly.Angel.DataTransport.ContactManagement.EntityClasses.OrganizationAddressEntity}
    base {Kelly.Angel.DataTransport.DataTransportBase}: {Kelly.Angel.DataTransport.ContactManagement.EntityClasses.OrganizationAddressEntity}
    _address: {Kelly.Angel.DataTransport.ContactManagement.EntityClasses.AddressEntity}
    _addressType: {Kelly.Angel.DataTransport.ContactManagement.EntityClasses.AddressTypeEntity}
    _status: {Kelly.Angel.DataTransport.ContactManagement.EntityClasses.StatusEntity}
    ActiveEnd: {9/29/2007 10:28:37 AM}
    ActiveStart: {7/16/2005 12:00:00 AM}
    ActiveStatus: Active
    Address: {Kelly.Angel.DataTransport.ContactManagement.EntityClasses.AddressEntity}
    AddressId: 885
    AddressType: {Kelly.Angel.DataTransport.ContactManagement.EntityClasses.AddressTypeEntity}
    AddressTypeId: 0
    CustomPropertiesOfType: Count = 0
    FieldsCustomPropertiesOfType: Count = 9
    IsMailing: false
    IsPhysical: true
    LLBLGenProEntityTypeValue: 9
    LLBLGenProIsInHierarchyOfType: None
    LLBLGenProIsSubType: false
    Note: "new desc                                                                                            "
    OrganizationAddressId: 44827
    OrganizationId: 0
    Primary: true
    Status: {Kelly.Angel.DataTransport.ContactManagement.EntityClasses.StatusEntity}
    StatusId: 0


And here is the same when I come through for the physical grid bound to the physical EntityView2:

?entity
{Kelly.Angel.DataTransport.ContactManagement.EntityClasses.OrganizationAddressEntity}
    base {Kelly.Angel.DataTransport.DataTransportBase}: {Kelly.Angel.DataTransport.ContactManagement.EntityClasses.OrganizationAddressEntity}
    _address: null
    _addressType: null
    _status: null
    ActiveEnd: null
    ActiveStart: null
    ActiveStatus: NotSet
    Address: null
    AddressId: 0
    AddressType: null
    AddressTypeId: 0
    CustomPropertiesOfType: Count = 0
    FieldsCustomPropertiesOfType: Count = 9
    IsMailing: 'entity.IsMailing' threw an exception of type 'System.NullReferenceException'
    IsPhysical: 'entity.IsPhysical' threw an exception of type 'System.NullReferenceException'
    LLBLGenProEntityTypeValue: 9
    LLBLGenProIsInHierarchyOfType: None
    LLBLGenProIsSubType: false
    Note: ""
    OrganizationAddressId: 0
    OrganizationId: 0
    Primary: false
    Status: null
    StatusId: 0

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 17-Jul-2007 16:11:27   

It seems the entity is not fetched.

just after

mailing = new EntityView2<OrganizationAddressEntity>(organization.Address, (OrganizationAddressFields.AddressTypeId == OrganizationAddressEntity.AddressTypeMailing));

What dou you have in mailing.Count, and in mailing(0) ?

Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 17-Jul-2007 16:18:42   

Count = 0 on both.

?physical.Count
0
?mailing.Count
0
?physical(0)
'WindowsApplication1.Form1.physical' is a 'field' but is used like a 'method'
?mailing(0)
'WindowsApplication1.Form1.mailing' is a 'field' but is used like a 'method'
?physical[0]
'physical[0]' threw an exception of type 'System.IndexOutOfRangeException'
    base {System.SystemException}: {"The index '0' is outside the list of entities in this view."}
?mailing[0]
'mailing[0]' threw an exception of type 'System.IndexOutOfRangeException'
    base {System.SystemException}: {"The index '0' is outside the list of entities in this view."}

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 17-Jul-2007 16:30:36   

Sorry for the (0) wink

Ok, so it seems there is a problem with the filter. Can you check the value in AddressTypeId ?

Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 17-Jul-2007 16:37:44   

Did that already, but ok. Here is pass from full list. There are only 2 addresses.

addrows method immediate window:

?entity.AddressTypeId 
0
?entity.AddressTypeId == OrganizationAddressEntity.AddressTypeMailing 
false
?entity.AddressTypeId == OrganizationAddressEntity.AddressTypePhysical 
true
?entity.AddressTypeId 
1
?entity.AddressTypeId == OrganizationAddressEntity.AddressTypeMailing 
true
?entity.AddressTypeId == OrganizationAddressEntity.AddressTypePhysical 
false

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 18-Jul-2007 11:20:49   

Very wierd !!

Let's try a couple of things just to be sure.

1- Use integers in the predicates:

physical = new EntityView2<OrganizationAddressEntity>(organization.Address, (OrganizationAddressFields.AddressTypeId == 0));
            mailing = new EntityView2<OrganizationAddressEntity>(organization.Address, (OrganizationAddressFields.AddressTypeId == 1));

2- Try using a binding source to databind to each dataGridView.

btw, which runtimeLibrary version are you using?

Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 18-Jul-2007 15:46:06   

Ok. Changed the predicates to integers:

physical = new EntityView2<OrganizationAddressEntity>(organization.Address, (OrganizationAddressFields.AddressTypeId == 1));
            mailing = new EntityView2<OrganizationAddressEntity>(organization.Address, (OrganizationAddressFields.AddressTypeId == 0));

Bound the grids to a new datasource that is tied to OrganizationAddressEntity:

this.organizationAddressEntityBindingSource.DataSource = typeof(Kelly.Angel.DataTransport.ContactManagement.EntityClasses.OrganizationAddressEntity);

EntityViews are still empty and grids are still displaying 0 rows.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 18-Jul-2007 15:57:07   

which runtimeLibrary version are you using?

The runtime library version is obtainable by rightclicking the SD.LLBLGen.Pro.ORMSupportClasses.NETxy.dll in windows explorer and then by selecting properties and the version tab. The version is then enlisted at the top as the fileversion. It has the typical format as 2.0.0.YYMMDD, or starting in 2007, the format 2.0.YY.MMDD

Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 18-Jul-2007 16:03:26   

Sorry, forgot that part.frowning Latest build of version 2.0. 2.0.0.0 Final Release date June 15th, 2007.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 18-Jul-2007 17:00:38   

I don't know what might cause this. I'll need your help to re-produce it. Could you please make a simple re-pro project (zipped), targeting Northwind, and attach it to this thread?

Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 18-Jul-2007 17:47:49   

Ok. I created a project against Northwind and it works. The problem must be on my end but I am clueless as to what it could be.

I did not attach the Northwind project as it does not help. I cannot attach the code I am working on because I am not allowed.

What do I do now??

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 18-Jul-2007 17:59:14   

I'll look into it in half an hour. Stay tuned.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 18-Jul-2007 19:02:26   

First of all: you really should post real code of your fetch. That's unclear now.

Second, what is the .NET type of OrganizationAddressFields.AddressTypeId ? Is that perhaps short or byte ? If so, you ran into an issue with the value compare predicated which can only compare values of the same type (we changed/fixed that in v2.5). So if OrganizationAddressFields.AddressTypeId is a short and returns 1 and the value you compare with is an int, you won't get any matches.

Could you check that for me, please? (and I assume the OrganizationAddressFields.AddressTypeId fields in the entities do have a value which is either 0 or 1 so there are entities which should match the filters)

Frans Bouma | Lead developer LLBLGen Pro
Harry
User
Posts: 73
Joined: 26-Jun-2007
# Posted on: 18-Jul-2007 19:32:00   

I agree with you on posting real code. You will just have to be understanding however that sometimes contractors are not allowed to post real code as it violates client agreements.

I did post as much as I could.

The type mismatch is what was causing my issues! The field is a byte and I was using an int, both in the direct call and in my wrapper property.flushed

I greatly appreciate everyones help!!!

Thank you!!!!

smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 18-Jul-2007 20:49:23   

Glad it's sorted! simple_smile

Frans Bouma | Lead developer LLBLGen Pro