Data missmatch using projection

Posts   
 
    
svuddhi
User
Posts: 16
Joined: 06-Dec-2006
# Posted on: 09-Feb-2007 08:12:51   

I am using .net 2005 and sql server 2005 and llbl pro 2.0 Through LLBL Pro I am fetching data from three tables and putting into in collection.Then I am trying to bind these data

to grid by using EntityProjection. In collection, correct value is showing for every field. But after binding

wrong data is showing in grid. In database one-to-one relation is there between Contact table and SponsorContact table . Again Between sponsorContact and SponsorAffiliateContact one-to-one relation is there. Between contact and ContactPhone one-to-many realtion is there ,between contact and office many-to-one relation is there.

What is the solution for that?

Here is my code:

EntityCollection<SponsorAffiliateContactEntity> sponsorContact = new    

EntityCollection<SponsorAffiliateContactEntity>(); IPrefetchPath2 prefetchForContact = new PrefetchPath2((int)EntityType.SponsorAffiliateContactEntity);

    prefetchForContact.Add(SponsorAffiliateContactEntity.PrefetchPathContactPhone);
    prefetchForContact.Add(SponsorAffiliateContactEntity.PrefetchPathOffice);
    adapterForCommon = new DataAccessAdapter();
    adapterForCommon.FetchEntityCollection(sponsorContact, null, prefetchForContact);
    if (sponsorContact.Count > 0)
    {
        //Using LLBLProjection's get the data into datatable
        DataTable dtsponsorContact = new DataTable();
        List<IEntityPropertyProjector> propertyProjectors = new List<IEntityPropertyProjector>();
        propertyProjectors.Add(new EntityPropertyProjector(ContactFields.ContactId, "ContactId"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactFields.LastName, "LastName"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactFields.FirstName, "FirstName"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactFields.Title, "Title"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactFields.Department, "Department"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactFields.PrimaryEmail, "PrimaryEmail"));
        propertyProjectors.Add(new EntityPropertyProjector(OfficeFields.Name, "Office"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactPhoneFields.AreaCode, "AreaCode"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactPhoneFields.Number, "Number"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactPhoneFields.Extension, "Extension"));
        propertyProjectors.Add(new EntityPropertyProjector(SponsorAffiliateContactFields.Company, "Affiliate"));
        propertyProjectors.Add(new EntityPropertyProjector(SponsorContactFields.EnableLogin, "EnableLogin"));
        sponsorContact.DefaultView.CreateProjection(propertyProjectors, dtsponsorContact);
        mngSponsorContactGrid.DataSource = dtsponsorContact;

        mngSponsorContactGrid.DataBind();

    Office,AreaCode,Number,Extension fields are showing wrong values.
Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 09-Feb-2007 08:48:37   

propertyProjectors.Add(new EntityPropertyProjector(ContactPhoneFields.AreaCode, "AreaCode"));

I don't think the above would work, since "ContactPhoneFields.AreaCode" is not considered as an EntityProperty for the SponsorAffiliateContactEntity.

Also since an entity should have many AreaCodes, which one should the system pick?

A simple solution for this is to use a DynamicList or a TypedList to fetch fields from different tables in a dataTable format, and so you won't have to project them into a dataTable.

svuddhi
User
Posts: 16
Joined: 06-Dec-2006
# Posted on: 09-Feb-2007 10:10:50   

svuddhi wrote:

I am using .net 2005 and sql server 2005 and llbl pro 2.0 Through LLBL Pro I am fetching data from three tables and putting into in collection.Then I am trying to bind these data

to grid by using EntityProjection. In collection, correct value is showing for every field. But after binding

wrong data is showing in grid. In database one-to-one relation is there between Contact table and SponsorContact table . Again Between sponsorContact and SponsorAffiliateContact one-to-one relation is there. Between contact and ContactPhone one-to-many realtion is there ,between contact and office many-to-one relation is there.

What is the solution for that?

Here is my code:

EntityCollection<SponsorAffiliateContactEntity> sponsorContact = new    

EntityCollection<SponsorAffiliateContactEntity>(); IPrefetchPath2 prefetchForContact = new PrefetchPath2((int)EntityType.SponsorAffiliateContactEntity);

    prefetchForContact.Add(SponsorAffiliateContactEntity.PrefetchPathContactPhone);
    prefetchForContact.Add(SponsorAffiliateContactEntity.PrefetchPathOffice);
    adapterForCommon = new DataAccessAdapter();
    adapterForCommon.FetchEntityCollection(sponsorContact, null, prefetchForContact);
    if (sponsorContact.Count > 0)
    {
        //Using LLBLProjection's get the data into datatable
        DataTable dtsponsorContact = new DataTable();
        List<IEntityPropertyProjector> propertyProjectors = new List<IEntityPropertyProjector>();
        propertyProjectors.Add(new EntityPropertyProjector(ContactFields.ContactId, "ContactId"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactFields.LastName, "LastName"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactFields.FirstName, "FirstName"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactFields.Title, "Title"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactFields.Department, "Department"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactFields.PrimaryEmail, "PrimaryEmail"));
        propertyProjectors.Add(new EntityPropertyProjector(OfficeFields.Name, "Office"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactPhoneFields.AreaCode, "AreaCode"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactPhoneFields.Number, "Number"));
        propertyProjectors.Add(new EntityPropertyProjector(ContactPhoneFields.Extension, "Extension"));
        propertyProjectors.Add(new EntityPropertyProjector(SponsorAffiliateContactFields.Company, "Affiliate"));
        propertyProjectors.Add(new EntityPropertyProjector(SponsorContactFields.EnableLogin, "EnableLogin"));
        sponsorContact.DefaultView.CreateProjection(propertyProjectors, dtsponsorContact);
        mngSponsorContactGrid.DataSource = dtsponsorContact;

        mngSponsorContactGrid.DataBind();

    Office,AreaCode,Number,Extension fields are showing wrong values.
svuddhi
User
Posts: 16
Joined: 06-Dec-2006
# Posted on: 09-Feb-2007 14:02:44   

How i will use my collection in dynamic list to display data in grid

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 12-Feb-2007 07:43:51   

Walaa said:

A simple solution for this is to use a DynamicList or a TypedList to fetch fields from different tables in a dataTable format, and so you won't have to project them into a dataTable.

I meant don't use an entity collection and prefetchPaths for the fetch, just directly use a DynamicList or a TypedList.

How i will use my collection in dynamic list to display data in grid

A DynamicList is a dataTable, so you can just bind it to the grid as you bind any dataTable to the grid.