Prefetch Path using m:1 relation problem

Posts   
 
    
jesterJP
User
Posts: 30
Joined: 21-Nov-2007
# Posted on: 10-May-2009 14:29:31   

Version 2.6 Final Build 2.6.8.1114 Using Adapter Model Database: MSSQL 2005

I have the following table structures:

OrgDomain Domain mgr_person_id

Person person_id last_nm

In the Designer, I have this relationship defined on the OrgDomain table:

Person (OrgDomain - Person (m:1))

Here is my code to fetch all the domains and their related managers:


            EntityCollection<OrgDomainEntity> _c = new EntityCollection<OrgDomainEntity>(new OrgDomainEntityFactory());
            IPrefetchPath2 _p = new PrefetchPath2((int)EntityType.OrgDomainEntity);
            _p.Add(OrgDomainEntity.PrefetchPathPerson);
            using (DataAccessAdapter _a = new DataAccessAdapter())
            {
                _a.FetchEntityCollection(_c, null, 0, null, _p);
                if (_c.Count == 0 && !bExactMatch)
                {
                    _a.FetchEntityCollection(_c, null);
                }
            }

When I fetch the collection, I get 10 Domain records, but the Person collection in each record is null. I have used SQL Profiler and there are 2 queries generated. One for the OrgDomain table and one for the Person table and they both return the necessary data.

What am I doing wrong?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-May-2009 22:13:58   

Please attach the DDL to recreate that two tables. Also, if possible attach the lgp file. And, What LLBLGen build version are you using (http://llblgen.com/TinyForum/Messages.aspx?ThreadID=7725)?

David Elizondo | LLBLGen Support Team
jesterJP
User
Posts: 30
Joined: 21-Nov-2007
# Posted on: 11-May-2009 03:10:15   

The LLBLGen Number is:

2.6 Final (June 6th, 200sunglasses

I created a stripped down database/project and recreated the issue. Attached is the lgp file here is the sql to create the two tables:


CREATE TABLE [dbo].[person](
    [person_id] [nvarchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [first_nm] [nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [last_nm] [nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [home_number] [nvarchar](14) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [mobile_phone] [nvarchar](14) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [corpdir_link] [nvarchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [email_address] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [inactive_in] [bit] NOT NULL,
    [inactive_dt] [datetime] NULL,
    [timestamp] [timestamp] NOT NULL,
 CONSTRAINT [p_person] PRIMARY KEY CLUSTERED 
(
    [person_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[org_domain](
    [domain] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [mgr_person_id] [nvarchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [p_domain] PRIMARY KEY CLUSTERED 
(
    [domain] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[org_domain]  WITH CHECK ADD  CONSTRAINT [f_person_08] FOREIGN KEY([mgr_person_id])
REFERENCES [dbo].[person] ([person_id])
GO

Attachments
Filename File size Added on Approval
domaintest.lgp 28,158 11-May-2009 03:11.22 Approved
psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 11-May-2009 06:36:20   

Is the casing different between the person_id in the person table and the mgr_person_id in the org_domain table (e.g. "person_1" and "PERSON_1")?

If this looks like it might be the problem try setting EntityFieldCore.CaseSensitiveStringHashCodes = false (it's a global setting, I believe).

http://llblgen.com/documentation/2.6/hh_goto.htm#Using%20the%20generated%20code/Adapter/gencode_prefetchpaths_adapter.htm

If there is no casing issue, ignore this message. simple_smile

HTH,

Phil

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 11-May-2009 09:34:55   

Most probably it's a casing issue. Please check this out for us.

jesterJP
User
Posts: 30
Joined: 21-Nov-2007
# Posted on: 11-May-2009 13:46:47   

All column names in my database are lower case. I added the suggested flag prior to issuing the Fetch and I have the same results.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 11-May-2009 23:39:33   

We are not talking about column names, but rather about the values of the PK and their corresponding FK fields.

Values should have an exact match, as these are compared as strings in .NET code.

jesterJP
User
Posts: 30
Joined: 21-Nov-2007
# Posted on: 11-May-2009 23:48:21   

Sorry for the confusion. Values are an exact match.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 12-May-2009 00:00:10   

Can you reproduce this on Northwind? If not then we will need a repro solution with database some test data.

jesterJP
User
Posts: 30
Joined: 21-Nov-2007
# Posted on: 12-May-2009 00:06:08   

I'll try to repro on Northwind.

jesterJP
User
Posts: 30
Joined: 21-Nov-2007
# Posted on: 12-May-2009 00:36:49   

Found the error. It was a problem with the data. There was an embedded space after the person_id in the person table. SQL happily ignored the space during joins and the only way to see it was to append a character to the end of the field to make the space show.

Thanks for you help!!!!!