Typed List problem with inheritence

Posts   
 
    
deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 27-Sep-2007 12:48:35   

Hi Guys,

I am using v2.5.07.0820 with .Net 2, SQL2005 and some Telerik RadControls.

In the database, we have an Employee table that inherits from User which inherits from Person.

I created a TypedList that uses the Employee table. Due to the inheritence I can't add User and Person as relations. Two fields in the TypedList are from the inherited Person table and one is from the inherited User table.

Here is my html:


<llblgenpro:llblgenprodatasource id="employeeCollectionDataSource" runat="server" datacontainertype="TypedList"
    typedlisttypename="preLink.Data.TypedListClasses.EmployeeTypedList, preLink.Data" enablepaging="True">
</llblgenpro:llblgenprodatasource>

<usercontrol:gridsearchcriteriacontrol id="gridSearchCriteriaControl" runat="server" 
    onsearchinvoked="gscSearchCriteria_SearchInvoked" onsearchcleared="gscSearchCriteria_SearchCleared" />
    
<p style="clear:left;">&nbsp;</p>

    
<prelink:prelinkradgrid id="personRadGrid" runat="server" useembeddedscripts="false"
    datasourceid="employeeCollectionDataSource" autogeneratecolumns="False" width="650px">
    <mastertableview datakeynames="EmployeeId">
        <columns>                   
            <radg:gridboundcolumn datafield="LastName" headertext="Surname" sortexpression="LastName" uniquename="LastName">
            </radg:gridboundcolumn>
            <radg:gridboundcolumn datafield="FirstName" headertext="Name" sortexpression="FirstName" uniquename="FirstName">
            </radg:gridboundcolumn> 
            <radg:gridboundcolumn datafield="Username" headertext="Username" sortexpression="Username" uniquename="Username">
            </radg:gridboundcolumn>             
            <radg:gridtemplatecolumn uniquename="EditColumn" itemstyle-horizontalalign="center">
                <itemtemplate>
                    <a href="/admin/test/details.aspx?personId=<%#Eval("EmployeeId")%>">Edit</a>                    
                </itemtemplate>
            </radg:gridtemplatecolumn>
          </columns>
    </mastertableview>
</prelink:prelinkradgrid>

When I try and run the page I get an exception:


The multi-part identifier "preLink.dbo.Person.FirstName" could not be bound.
The multi-part identifier "preLink.dbo.Person.LastName" could not be bound.
The multi-part identifier "preLink.dbo.User.UserName" could not be bound. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: The multi-part identifier "preLink.dbo.Person.FirstName" could not be bound.
The multi-part identifier "preLink.dbo.Person.LastName" could not be bound.
The multi-part identifier "preLink.dbo.User.UserName" could not be bound.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[SqlException (0x80131904): The multi-part identifier "preLink.dbo.Person.FirstName" could not be bound.
The multi-part identifier "preLink.dbo.Person.LastName" could not be bound.
The multi-part identifier "preLink.dbo.User.UserName" could not be bound.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +862234
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +739110
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1956
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
   System.Data.SqlClient.SqlDataReader.get_MetaData() +62
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +903
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
   System.Data.SqlClient.SqlCommand.ExecuteScalar() +137
   SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.ExecuteScalar() +71

[ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: The multi-part identifier "preLink.dbo.Person.FirstName" could not be bound.
The multi-part identifier "preLink.dbo.Person.LastName" could not be bound.
The multi-part identifier "preLink.dbo.User.UserName" could not be bound.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.]
   SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.ExecuteScalar() +222
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteScalarQuery(IRetrievalQuery queryToExecute, ITransaction containingTransaction) +152
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.GetDbCount(IEntityFields fields, ITransaction containingTransaction, IPredicate filter, IRelationCollection relations, IGroupByCollection groupByClause, Boolean allowDuplicates) +161
   preLink.Data.TypedListClasses.EmployeeTypedList.GetDbCount(Boolean allowDuplicates, IPredicateExpression filter, IRelationCollection relations, GroupByCollection groupByClause) +179
   SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.ExecuteSelectTypedList(Int32 pageSize, Int32 pageNumber, DataSourceSelectArguments arguments) +327
   SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +134
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
   Telerik.WebControls.GridTableView.PerformSelect() +4
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
   Telerik.WebControls.GridTableView.DataBind() +343
   Telerik.WebControls.RadGrid.DataBind() +77
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +41
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360

The SQL that is generated is:


SELECT COUNT(*) AS NumberOfRows FROM (SELECT [preLink].[dbo].[Employee].[EmployeeId], [preLink].[dbo].[Person].[FirstName], [preLink].[dbo].[Person].[LastName], [preLink].[dbo].[User].[UserName] FROM [preLink].[dbo].[Employee] ) TmpResult

Am I doing something wrong?

The help is greatly appreciated.

Thanks, Russell.

Attachments
Filename File size Added on Approval
Untitled.png 36,491 27-Sep-2007 12:49.07 Approved
Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 27-Sep-2007 15:55:18   

In the database, we have an Employee table that inherits from User which inherits from Person.

Assuming the following: 1- You have 3 tables in the database (EMPLOYEE -> USER -> PERSON) 2- The PKs of them are all linked together to realize the 1:1 inheritance relation. ( EMPLOYEE PK is also the FK to the USER PK) ( USER PK is also the FK to the PERSON PK) 3- In the LLBLGen Pro Designer, the inheritance relation is realized as a a TargetPerEntity Inheritance Hierarchy.

I couldn't reproduce your issue.

I created a TypedList that uses the Employee table. Due to the inheritence I can't add User and Person as relations. Two fields in the TypedList are from the inherited Person table and one is from the inherited User table.

  • I have a (Parent -> Child1 -> Child11) entities in an TargetPerEntity Inheritance Hierarchy.
  • I created a TypedList.
  • I've added the Child11 entity to the TL, then I've added the Child1 & Parent to the TL.
  • I selected fields from each entity.
  • Generated code and built a solution and nothing went wrong whatsoever.

I'll attach a repro solution. Attached, SelfServicing, Windows application and a Web application too. Please run the database script to create the (3-tables) database first.

deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 27-Sep-2007 16:52:35   

Hi Walaa,

Thanks for the reply.

I opened your project file but none of the entities were sub types? That is why you were able to add all the related tables to the TL.

You shouldn't be adding the base entities to the TL anway as the sub-type entity already has all the base entities' fields?

I have attached a database diagram and screen shot of the designer where it shows how Employee is a sub-type of User and User is a sub-type of Person.

Thanks, Russell

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 27-Sep-2007 22:57:00   

Oh Sorry I've missed that.

I updated the lgp file (will attach the new one)ATTACHED. 1- deleted the TypedList. 2- RightClick on the Entities node -> Construct Target-per-entity Hierarchies 3- Created a TypedList (TL1) -> Added Child11 entity ONLY. 4- Re-geenerate Code... 5- Rebuild my solutiuon..... and everything worked perfectly AGAIN. simple_smile

Still can't reproduce your issue.

Attachments
Filename File size Added on Approval
TL-INH-Test.lgp 34,740 27-Sep-2007 22:57.36 Approved
deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 28-Sep-2007 09:16:49   

Hi Walaa,

THanks for all the help. I see that yours works.

In my solution I set enablepaging="false" on the LLBLGenProDataSource and the error is gone?? Now the page worked and it genreated the following SQL:


SELECT [LPA_L3].[EmployeeId], [LPA_L1].[FirstName], [LPA_L1].[LastName], [LPA_L2].[UserName] FROM (( [preLink].[dbo].[Person] [LPA_L1]  INNER JOIN [preLink].[dbo].[User] [LPA_L2]  ON  [LPA_L1].[PersonId]=[LPA_L2].[UserId]) INNER JOIN [preLink].[dbo].[Employee] [LPA_L3]  ON  [LPA_L2].[UserId]=[LPA_L3].[EmployeeId])

So how do I get the paging to work on my datasource?

  • Russell
Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 28-Sep-2007 12:12:47   

I set EnablePaging to true on the LLBLGenProDataSource, and I still have no problems. You may try it with my solution.

Would you please create and attach a repro solution? So we can see what's going wrong.

deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 28-Sep-2007 14:49:19   

Hi Walaa,

Sorry for the late reply, been a really hectic day. Thanks for the response.

=) I managed to break yours as well. If you set allowpaging="true" on the GridView and enablepaging="true" on the llblgenprodatasource it throws the same error.

Thanks, Russell

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 28-Sep-2007 16:21:43   

Reproduced. We'll be looking into it.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 01-Oct-2007 13:42:31   

It's a bug in DaoBase.GetDbCount, it affects any typedlist.GetDbCount(), as it doesn't add the relations for a typedlist with inherited elements IF there's no relation in the typedlist.

This is done for a fetch, hence it works there, but not in GetDbCount. Will fix. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 01-Oct-2007 13:55:33   

Hi Otis,

Thanks for the help.

Not to be pushy but how and when can we expect a fix? I am willing to use a "development" version in the mean time.

THanks, Russell

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 01-Oct-2007 15:23:34   

deathwish wrote:

Hi Otis,

Thanks for the help.

Not to be pushy but how and when can we expect a fix? I am willing to use a "development" version in the mean time.

THanks, Russell

In the next version... wink No, just kidding.

I'm done testing the fix, it was tougher than expected, as I ran into a glitch with the aliasing engine, where twice the same relation collection used would cause problems. This has been fixed now. I'll attach a build to this post. just a sec.

Edit: Attached

Frans Bouma | Lead developer LLBLGen Pro
deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 02-Oct-2007 09:12:13   

Hi Otis/Walaa,

Thanks very much for the great support.

Posts: 23
Joined: 28-Aug-2008
# Posted on: 22-Feb-2010 15:36:35   

Hi I'm having same error.

I have a Record base table and Member table inherit's from record and some other tables. I have a typed list "MemberList".

Fetching this typed list:


public ITypedListLgp2 GetFormTypedList(TypedListTypes listType, long UserId) {
            ITypedListLgp2 list = daHelper.CreateNewList(listType); // Create requested list by listType (defined enum)
            IPredicateExpression filter = daHelper.CreateTypeFilterByListName(list.ToString()); // Creates record type filter if entity inherited from the record entity, daHelper function below
            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            int llblgenEntityTypeValue = (int)daHelper.ListTypeToEntityType(listType);
            if (daHelper.EntityIsInherited(llblgenEntityTypeValue)) { // Check is requested list main entity is inherited from Record
                UserEntity user = GetUser(UserId); // Get Current User Entity
                bucket = daHelper.CreateUserBucket(user); // daHelper function below
                daHelper.MergeFilter(bucket.PredicateExpression, filter); // daHelper function below
            } else {
                bucket.PredicateExpression.Add(filter);
            }
            adapter.FetchTypedList(list.GetFieldsInfo(), (DataTable)list, bucket, true);
            return list;
        }

/// daHelper Functions Start

public IPredicateExpression CreateTypeFilterByListName(string ListName) {
            IPredicateExpression filter = null;
            TypedListTypes listType = (TypedListTypes)Enum.Parse(typeof(TypedListTypes), ListName);
            EntityType TypeOfEntity = ListTypeToEntityType(listType);
            filter = CreateTypeFilter((int)TypeOfEntity);
            return filter;
        }


public IRelationPredicateBucket CreateUserBucket(UserEntity user) {
            IRelationPredicateBucket bucket = new RelationPredicateBucket();
            //
            //bucket.Relations.ObeyWeakRelations = true;
            if (user.Role.Organization.FIsRoot == false) { // If not root organization user restrict user
                bucket.Relations.Add(RecordEntity.Relations.UserEntityUsingFkCreatedBy);
                bucket.Relations.Add(UserEntity.Relations.RoleEntityUsingFkRole);
                bucket.PredicateExpression.Add(RoleFields.FkOrganization == user.Role.Organization.PkId);
                //bucket.PredicateExpression.Add(OrganizationFields.PkId == user.Role.Organization.PkId);
            }
            //
            return bucket;
        }

public IPredicateExpression MergeFilter(IPredicateExpression firstFilter, IPredicateExpression secondFilter) {
            //IPredicateExpression filter = new PredicateExpression();
            if (firstFilter == null) return null;
            if (secondFilter != null) {
                if (secondFilter.Count > 0) {
                    if (firstFilter.Count > 0) firstFilter.AddWithAnd(secondFilter);
                    else firstFilter.Add(secondFilter);
                }
            }
            return firstFilter;
        }

// dahelper Functions End

When I call GetFormTypedList function for "MemberList" it throw "An exception was caught during the execution of a retrieval query: The multi-part identifier "passref.dbo.pr_organization.f_name" could not be bound.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception." Exception.

QueryExecuted :

"\r\n\tQuery: SELECT [LPA_L2].[pk_id] AS [PkId], [LPA_L2].[fk_organization] AS [FkOrganization], [passref].[dbo].[pr_organization].[f_name] AS [FOrganizationName], [LPA_L2].[fk_division] AS [FkDivision], [LPA_L3].[f_name] AS [FDivisionName], [LPA_L2].[fk_group] AS [FkGroup], [LPA_L4].[f_name] AS [FGroupName], [LPA_L2].[fk_title] AS [FkTitle], [LPA_L5].[f_name] AS [FTitleName], [LPA_L2].[f_is_active] AS [FisActive], [LPA_L2].[f_national_id] AS [FnationalId], [LPA_L2].[f_employee_id] AS [FemployeeId], [LPA_L2].[f_student_id] AS [FstudentId], [LPA_L2].[f_name] AS [Fname], [LPA_L2].[f_sirname] AS [Fsirname], [LPA_L2].[f_e_mail] AS [Femail], [LPA_L2].[f_gsm] AS [Fgsm], [LPA_L2].[f_work_phone] AS [FworkPhone] FROM (((( [passref].[dbo].[pr_record] [LPA_L1]  LEFT JOIN [passref].[dbo].[pr_member] [LPA_L2]  ON  [LPA_L1].[pk_id]=[LPA_L2].[pk_id]) LEFT JOIN [passref].[dbo].[pr_division] [LPA_L3]  ON  [LPA_L1].[pk_id]=[LPA_L3].[pk_id]) LEFT JOIN [passref].[dbo].[pr_group] [LPA_L4]  ON  [LPA_L1].[pk_id]=[LPA_L4].[pk_id]) LEFT JOIN [passref].[dbo].[pr_title] [LPA_L5]  ON  [LPA_L1].[pk_id]=[LPA_L5].[pk_id]) WHERE ( ( ( [LPA_L1].[fk_type] = @FkType1)))\r\n\tParameter: @FkType1 : Byte. Length: 1. Precision: 3. Scale: 0. Direction: Input. Value: 11.\r\n"

But its wrong.

Wright SQL is:


declare @FkType1 smallint;
set @FkType1 = 0;
SELECT 
[LPA_L2].[pk_id] AS [PkId], [LPA_L2].[fk_organization] AS [FkOrganization], 
[LPA_L6].[f_name] AS [FOrganizationName], [LPA_L2].[fk_division] AS [FkDivision], 
[LPA_L3].[f_name] AS [FDivisionName], [LPA_L2].[fk_group] AS [FkGroup], [LPA_L4].[f_name] AS [FGroupName], 
[LPA_L2].[fk_title] AS [FkTitle], [LPA_L5].[f_name] AS [FTitleName], [LPA_L2].[f_is_active] AS [FisActive], 
[LPA_L2].[f_national_id] AS [FnationalId], [LPA_L2].[f_employee_id] AS [FemployeeId], [LPA_L2].[f_student_id] AS [FstudentId], 
[LPA_L2].[f_name] AS [Fname], [LPA_L2].[f_sirname] AS [Fsirname], [LPA_L2].[f_e_mail] AS [Femail], [LPA_L2].[f_gsm] AS [Fgsm], 
[LPA_L2].[f_work_phone] AS [FworkPhone] 
FROM (
    (
        ((
            ([passref].[dbo].[pr_record] [LPA_L1]  INNER JOIN [passref].[dbo].[pr_member] [LPA_L2]  ON  [LPA_L1].[pk_id]=[LPA_L2].[pk_id]) 
            LEFT JOIN [passref].[dbo].[pr_organization] [LPA_L6]  ON  [LPA_L2].[fk_organization]=[LPA_L6].[pk_id]) 
            LEFT JOIN [passref].[dbo].[pr_division] [LPA_L3]  ON  [LPA_L2].[fk_division]=[LPA_L3].[pk_id]) 
        LEFT JOIN [passref].[dbo].[pr_group] [LPA_L4]  ON  [LPA_L2].[fk_group]=[LPA_L4].[pk_id]) 
    LEFT JOIN [passref].[dbo].[pr_title] [LPA_L5]  ON  [LPA_L2].[fk_title]=[LPA_L5].[pk_id])
--WHERE ( ( ( [LPA_L1].[fk_type] = @FkType1)))

I am attaching Database SQL files and LLBLGEN Project...

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 22-Feb-2010 15:49:03   

Please follow posting guidelines: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7725

1- Don't resurrect threads, please create a new one. 2- Post version information (runtime library version/build), please.

I'll close this thread, and will be waiting for the new thread.

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 22-Feb-2010 17:56:16   

Continuation of thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=17461

(and it was fixed)

Frans Bouma | Lead developer LLBLGen Pro