GetDbCount and Inheritance

Posts   
 
    
Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 03-Oct-2007 02:56:49   

I have a problem where the FetchEntityCollection of an inheritance hierarchy works however the GetDbCount does not. It fails with the typical "The multi-part identifier could not be bound." The code is below. The FetchEntityCollection doesn't need the relations for specified entity because of the polymorphic fetch. What do I need to do to get the GetDbCount to do the same? Should I use the entity factory?


        public InfrastructureCentral.BLInterfaces.SearchResults.IResultsEntityCollection QuickContactSearch(IRelationPredicateBucket bucket, Type contacttype, int maxnumofitems, ISortExpression sort, IPrefetchPath2 prefetch, ExcludeIncludeFieldsList fields, int pagenumber, int pagesize)
        {
            // Create an object of the passed type and make sure it is of the hierarchy
            object _ot = contacttype.InvokeMember(string.Empty, System.Reflection.BindingFlags.CreateInstance, System.Type.DefaultBinder, null, null);
            if (_ot is ContactEntity)
            {
                // Create the entity collection of the passed type
                Type _collectionType = typeof(EntityCollection<>);
                Type _constructedType = _collectionType.MakeGenericType(contacttype);
                object o = Activator.CreateInstance(_constructedType);
                

                using (DataAccessAdapter _adapter = new DataAccessAdapter(true))
                {
                    
                    

                    // Fetch the entity collection
                    _adapter.FetchEntityCollection(o as IEntityCollection2, bucket, maxnumofitems, sort, prefetch, fields, pagenumber, pagesize);
                    IEntityCollection2 _searchResults = o as IEntityCollection2;

                    // Not sure if the factory classes will help
                    //DAL.FactoryClasses.ContactEntityFactory _cntc = new DAL.FactoryClasses.ContactEntityFactory();
                    //_cntc.CreateHierarchyRelations()

                    // Get the dbcount
                    int _count;
                    if (pagesize > 0)
                        _count = _adapter.GetDbCount(_searchResults, bucket);
                    else
                        _count = _searchResults.Count;
                    return new SearchService.ResultsEntityCollection(_searchResults, _count) as InfrastructureCentral.BLInterfaces.SearchResults.IResultsEntityCollection;
                }
            }
            throw new ArgumentException(String.Format("The passed entity type {0} is not of the type ContactEntity", contacttype.ToString()));
        }

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 03-Oct-2007 11:23:12   

Which runtime library version are you using? (ref: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7717)

Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 03-Oct-2007 12:40:11   

v2.0.50727

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 03-Oct-2007 12:56:38   

That's not the correct RTL version, please check the link I've posted above.

Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 03-Oct-2007 13:04:14   

Walaa wrote:

That's not the correct RTL version, please check the link I've posted above.

Sorry, how about

2.5.07.0822

Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 03-Oct-2007 19:28:55   

The sql queries below are what llblgen sends to sql when querying for a user. The first code block is for the fetchentitycollection and the second code block is for the getdbcount. The fetchentitycollection command works properly and does the correct joins. The GetDBCount command does not work as it does not add all of the proper joins.


exec sp_executesql N'SELECT DISTINCT TOP 20 [ICDEV].[PointOfContact].[Contact].[ContactGuid] AS [F0], [ICDEV].[PointOfContact].[Contact].[Name] AS [F1], [ICDEV].[PointOfContact].[Contact].[Email] AS [F2], [ICDEV].[PointOfContact].[Contact].[WebPage] AS [F3], 
[ICDEV].[PointOfContact].[Contact].[Deleted] AS [F4], [ICDEV].[PointOfContact].[IndividualContact].[ContactGuid] AS [F5], 
[ICDEV].[PointOfContact].[IndividualContact].[FirstName] AS [F6], [ICDEV].[PointOfContact].[IndividualContact].[MiddleName] AS [F7], 
[ICDEV].[PointOfContact].[IndividualContact].[LastName] AS [F8], [ICDEV].[PointOfContact].[IndividualContact].[PrimaryPhone] AS [F9], 
[ICDEV].[PointOfContact].[IndividualContact].[SecondaryPhone] AS [F10], [ICDEV].[PointOfContact].[IndividualContact].[CellPhone] AS [F11], 
[ICDEV].[PointOfContact].[IndividualContact].[Pager] AS [F12], [ICDEV].[PointOfContact].[IndividualContact].[Fax] AS [F13], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[ContactGuid] AS [F14], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[ShortUserId] AS [F15], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[UserId] AS [F16], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[Title] AS [F17], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[Department] AS [F18], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[Office] AS [F19], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[ManagerUserId] AS [F20], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[AssistantUserId] AS [F21], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[DomainName] AS [F22], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[DistinguishedName] AS [F23], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[SipPrimaryUserEmailAddress] AS [F24] FROM (( [ICDEV].[PointOfContact].[Contact]  INNER JOIN [ICDEV].[PointOfContact].[IndividualContact]  ON  [ICDEV].[PointOfContact].[Contact].[ContactGuid]=[ICDEV].[PointOfContact].[IndividualContact].[ContactGuid]) INNER JOIN [ICDEV].[PointOfContact].[ActiveDirectoryUser]  ON  [ICDEV].[PointOfContact].[IndividualContact].[ContactGuid]=[ICDEV].[PointOfContact].[ActiveDirectoryUser].[ContactGuid]) WHERE ( ( ( [ICDEV].[PointOfContact].[Contact].[Name] LIKE @Name1 OR [ICDEV].[PointOfContact].[IndividualContact].[FirstName] LIKE @FirstName2 OR [ICDEV].[PointOfContact].[IndividualContact].[LastName] LIKE @LastName3 OR [ICDEV].[PointOfContact].[ActiveDirectoryUser].[ShortUserId] LIKE @ShortUserId4)) AND ( [ICDEV].[PointOfContact].[ActiveDirectoryUser].[ContactGuid] IS NOT NULL)) ORDER BY [ICDEV].[PointOfContact].[Contact].[Name] ASC',N'@Name1 nvarchar(5),@FirstName2 nvarchar(5),@LastName3 nvarchar(5),@ShortUserId4 varchar(5)',@Name1=N'Bran%',@FirstName2=N'Bran%',@LastName3=N'Bran%',@ShortUserId4='Bran%'


exec sp_executesql N'SELECT COUNT(*) AS NumberOfRows FROM (SELECT [ICDEV].[PointOfContact].[Contact].[ContactGuid] AS [ContactGuid_ContactEntity], [ICDEV].[PointOfContact].[Contact].[Name], [ICDEV].[PointOfContact].[Contact].[Email], [ICDEV].[PointOfContact].[Contact].[WebPage], 
[ICDEV].[PointOfContact].[Contact].[Deleted], [ICDEV].[PointOfContact].[IndividualContact].[ContactGuid] AS [ContactGuid_IndividualContactEntity], [ICDEV].[PointOfContact].[IndividualContact].[FirstName], [ICDEV].[PointOfContact].[IndividualContact].[MiddleName], [ICDEV].[PointOfContact].[IndividualContact].[LastName], [ICDEV].[PointOfContact].[IndividualContact].[PrimaryPhone], [ICDEV].[PointOfContact].[IndividualContact].[SecondaryPhone], [ICDEV].[PointOfContact].[IndividualContact].[CellPhone], [ICDEV].[PointOfContact].[IndividualContact].[Pager], [ICDEV].[PointOfContact].[IndividualContact].[Fax], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[ContactGuid], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[ShortUserId], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[UserId], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[Title], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[Department], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[Office], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[ManagerUserId], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[AssistantUserId], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[DomainName], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[DistinguishedName], [ICDEV].[PointOfContact].[ActiveDirectoryUser].[SipPrimaryUserEmailAddress] FROM ( [ICDEV].[PointOfContact].[Contact]  INNER JOIN [ICDEV].[PointOfContact].[IndividualContact]  ON  [ICDEV].[PointOfContact].[Contact].[ContactGuid]=[ICDEV].[PointOfContact].[IndividualContact].[ContactGuid]) WHERE ( ( ( [ICDEV].[PointOfContact].[Contact].[Name] LIKE @Name1 OR [ICDEV].[PointOfContact].[IndividualContact].[FirstName] LIKE @FirstName2 OR [ICDEV].[PointOfContact].[IndividualContact].[LastName] LIKE @LastName3 OR [ICDEV].[PointOfContact].[ActiveDirectoryUser].[ShortUserId] LIKE @ShortUserId4)))) TmpResult',N'@Name1 nvarchar(5),@FirstName2 nvarchar(5),@LastName3 nvarchar(5),@ShortUserId4 varchar(5)',@Name1=N'Bran%',@FirstName2=N'Bran%',@LastName3=N'Bran%',@ShortUserId4='Bran%'

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 04-Oct-2007 14:35:03   

Looks like the bug reported very recently in selfservicing: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=11402

apparently the adapter code also has this issue. I did look at the adapter code briefly and didn't see similarities with the buggy code in the selfservicing routine, but I'll re-test to see if it indeed needs patching as well (the routines work differently, so it's not just looking if the code is the same)

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 04-Oct-2007 17:19:14   

Reproduced

Frans Bouma | Lead developer LLBLGen Pro
Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 04-Oct-2007 17:31:42   

Otis wrote:

Reproduced

Great thanks for checking on it. I kept looking at the code over and over again to make sure it wasn't something that I was missing.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 04-Oct-2007 18:22:22   

Brandt wrote:

Otis wrote:

Reproduced

Great thanks for checking on it. I kept looking at the code over and over again to make sure it wasn't something that I was missing.

It indeed doesn't add the relations. To work around it, do a GetDbCount by passing in the ID field of the entity. I hope to have a fix available for this today.

(edit) fixed in next build. (10042007), which is uploaded within half an hour).

Frans Bouma | Lead developer LLBLGen Pro
Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 05-Oct-2007 12:49:24   

Otis wrote:

Brandt wrote:

Otis wrote:

Reproduced

Great thanks for checking on it. I kept looking at the code over and over again to make sure it wasn't something that I was missing.

It indeed doesn't add the relations. To work around it, do a GetDbCount by passing in the ID field of the entity. I hope to have a fix available for this today.

(edit) fixed in next build. (10042007), which is uploaded within half an hour).

Thanks Otis, Perfect support as usual.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 05-Oct-2007 13:30:40   

We discovered a bug in yesterday's fix. Please obtain the build attached to this thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=11485

or wait for the build this afternoon. Sorry for this major inconvenience...

Frans Bouma | Lead developer LLBLGen Pro
Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 05-Oct-2007 15:13:39   

Otis wrote:

We discovered a bug in yesterday's fix. Please obtain the build attached to this thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=11485

or wait for the build this afternoon. Sorry for this major inconvenience...

Its no problem. I can wait.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 05-Oct-2007 21:56:54   

It's available simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 06-Oct-2007 00:13:01   

Otis wrote:

It's available simple_smile

Thanks Otis. And once again I must commend the support for your product. By far the best and fastest customer support in the industry, and by far the most capable and complete O/R mapper out there. Good work!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 06-Oct-2007 11:26:39   

Thanks for the compliments! smile

Frans Bouma | Lead developer LLBLGen Pro