Typed list alias not mapped

Posts   
 
    
Dave Erwin
User
Posts: 12
Joined: 04-Oct-2010
# Posted on: 04-Nov-2010 18:20:40   

LLBLGen 3.0 10/22/2010, targeting NHibernate framework.

I am trying to create my first typed list. I created a list selecting a few fields from an entity (DealerEntity) that works on it's own.

public static IList<DealerListTypedListRow> FetchDealerList() {
            var _sessionFactory = StructureMap.ObjectFactory.Container.GetInstance<ISessionFactory>();

            IList<DealerListTypedListRow> list = new List<DealerListTypedListRow>();

            var session = _sessionFactory.OpenSession();
            list = TypedListQueryFactory.GetDealerListTypedListQuery(session).List<DealerListTypedListRow>();
            return list;
        }

When I try to get the list I get this exception:

{"D is not mapped [select D.Name as Name, D.City as City, D.State as State, D.PhoneNumber1 as PhoneNumber1, D.IsActive as IsActive from D]"} System.Exception {NHibernate.Hql.Ast.ANTLR.QuerySyntaxException}

It seems like the "from DealerEntity D" is missing but I'm not sure why?

If I create the query using session.CreateCriteria with "from DealerEntity D" added it works.

I've searched around the forums and google to figure out what I'm missing but I haven't had any luck.

Thanks.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 04-Nov-2010 21:12:22   

Could you post the generated code for the TypedList please...?

Thanks

Matt

Dave Erwin
User
Posts: 12
Joined: 04-Oct-2010
# Posted on: 04-Nov-2010 21:22:05   

MTrinder wrote:

Could you post the generated code for the TypedList please...?

Thanks

Matt

//------------------------------------------------------------------------------
// <auto-generated>This code was generated by LLBLGen Pro v3.0.</auto-generated>
//------------------------------------------------------------------------------
using System;
using NHibernate;
using NHibernate.Transform;
using TrailerWorks.Factories.NHibernate.TypedListClasses;

namespace TrailerWorks.Factories.NHibernate
{
    /// <summary>Class which contains the typed list query factory methods.</summary>
    public static partial class TypedListQueryFactory
    {
        /// <summary>Creates an IQuery to fetch the typed list 'DealerList' into instances of DealerListTypedListRow</summary>
        /// <param name="session">The session to use for fetching.</param>
        /// <returns>Query to fetch the typed list</returns>
        public static IQuery GetDealerListTypedListQuery(ISession session)
        {
            return GetDealerListTypedListQuery(session, string.Empty);
        }

        /// <summary>Creates an IQuery to fetch the typed list 'DealerList' into instances of DealerListTypedListRow</summary>
        /// <param name="session">The session to use for fetching.</param>
        /// <param name="additionalQueryFragment">The additional query fragment, in HQL syntax.</param>
        /// <returns>Query to fetch the typed list</returns>
        /// <remarks>Entities are aliased either by the alias specified in the typedlist, or using the pattern a_<i>entityname_lowercase</i>.</remarks>
        public static IQuery GetDealerListTypedListQuery(ISession session, string additionalQueryFragment)
        {
            return ProduceQuery<DealerListTypedListRow>(session, "select D.Id as Id, D.Name as Name, D.City as City, D.State as State, D.PhoneNumber1 as PhoneNumber1, D.IsActive as IsActive from D", additionalQueryFragment);
        }

        /// <summary>Produces the IQuery from the parameters specified</summary>
        /// <typeparam name="TRow">the typedlist row type</typeparam>
        /// <param name="session">The session.</param>
        /// <param name="queryString">The query string.</param>
        /// <param name="additionalQueryFragment">The additional query fragment.</param>
        /// <returns>the query to produce</returns>
        private static IQuery ProduceQuery<TRow>(ISession session, string queryString, string additionalQueryFragment)
        {
            string queryStringToUse = queryString;
            if(!string.IsNullOrEmpty(additionalQueryFragment))
            {
                queryStringToUse += string.Format(" {0}", additionalQueryFragment);
            }
            IQuery query = session.CreateQuery(queryStringToUse);
            query.SetResultTransformer(new AliasToBeanResultTransformer(typeof(TRow)));
            return query;
        }
    }
}

//------------------------------------------------------------------------------
// <auto-generated>This code was generated by LLBLGen Pro v3.0.</auto-generated>
//------------------------------------------------------------------------------
using System;
using System.ComponentModel;

namespace TrailerWorks.Factories.NHibernate.TypedListClasses
{
    /// <summary>Class which represents the typed list 'DealerList'.</summary>
    /// <remarks>Contains the following entity definition(s):
    /// Entity: DealerEntity.  Aliassed as: D <br/>
    /// </remarks>
    public partial class DealerListTypedListRow
    {
        #region Class Member Declarations
        private System.Int32 _id;
        private System.String _name;
        private System.String _city;
        private System.String _state;
        private System.String _phoneNumber1;
        private System.Boolean _isActive;
        #endregion

        /// <summary>Initializes a new instance of the <see cref="DealerListTypedListRow"/> class.</summary>
        public DealerListTypedListRow()
        {
            _id = default(System.Int32);
            _name = default(System.String);
            _city = default(System.String);
            _state = default(System.String);
            _phoneNumber1 = default(System.String);
            _isActive = default(System.Boolean);
        }


        #region Class Property Declarations
        /// <summary>Gets / sets the Id field. Mapped onto 'D.Id'</summary>
        public virtual System.Int32 Id
        {
            get { return _id; }
            set { _id = value;}
        }
        
        /// <summary>Gets / sets the Name field. Mapped onto 'D.Name'</summary>
        public virtual System.String Name
        {
            get { return _name; }
            set { _name = value;}
        }
        
        /// <summary>Gets / sets the City field. Mapped onto 'D.City'</summary>
        public virtual System.String City
        {
            get { return _city; }
            set { _city = value;}
        }
        
        /// <summary>Gets / sets the State field. Mapped onto 'D.State'</summary>
        public virtual System.String State
        {
            get { return _state; }
            set { _state = value;}
        }
        
        /// <summary>Gets / sets the PhoneNumber1 field. Mapped onto 'D.PhoneNumber1'</summary>
        public virtual System.String PhoneNumber1
        {
            get { return _phoneNumber1; }
            set { _phoneNumber1 = value;}
        }
        
        /// <summary>Gets / sets the IsActive field. Mapped onto 'D.IsActive'</summary>
        public virtual System.Boolean IsActive
        {
            get { return _isActive; }
            set { _isActive = value;}
        }
        
        #endregion
    }
}



MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 04-Nov-2010 21:32:09   

Thanks for that. Do you have the alias "D" defined in the TypedList designer ? If so, does it work correctly if you remove the alias (it's only really needed if you have the same table in the query more than once)

Matt

Dave Erwin
User
Posts: 12
Joined: 04-Oct-2010
# Posted on: 04-Nov-2010 21:41:20   

MTrinder wrote:

Thanks for that. Do you have the alias "D" defined in the TypedList designer ? If so, does it work correctly if you remove the alias (it's only really needed if you have the same table in the query more than once)

Matt

Yes "D" is defined. It doesn't work without it either, it just says the a_DealerEntity is unmapped (or whatever the default alias is).

I had the "D" in there because DealerEntity has a m:1 to a salesperson entity and I eventually want the salesperson name in the list. DealerEntity also has a 1:m with a dealer note entity.

I'm just starting to mess with typed lists. I am looking to be able to create a read only list of dealers for a selection screen in the app. I don't need the whole dealer entity graph for the selection screen so I thought a typed list might do what I want. Maybe I'm on the wrong track here.

Thanks,

Dave Erwin

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 05-Nov-2010 13:23:51   

Hmm. I think it's a bug related to having a single entity in the typedlist. Our tests have typedlists with relationships. Will look into it.

btw, there's a workaround for you: map the table as a typedview and remove any fields you don't like. E.g. I mapped a typedview on the customers table, removed half the fields and fetched it:

var tvs = session.CreateCriteria(typeof(CustomerTVTypedViewRow))
                        .Add(Restrictions.Eq("Country", "USA"))
                        .List<CustomerTVTypedViewRow>();

for single table typedlists this might be a good alternative in the meantime. They're readonly as well.

I can reproduce your typedlist problem in a typedlist with 1 entity and no relationships. Looking into that now.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 05-Nov-2010 13:48:26   

Fixed it. See attached template. Place that template in: <llblgen pro install folder>\Frameworks\NHibernate\Templates\Shared\C#\

(as administrator, if you're using vista/7)

Of course regenerate your code simple_smile

Attachments
Filename File size Added on Approval
typedListQueryFactoryClass.lpt 4,940 05-Nov-2010 13:48.31 Approved
Frans Bouma | Lead developer LLBLGen Pro
Dave Erwin
User
Posts: 12
Joined: 04-Oct-2010
# Posted on: 05-Nov-2010 16:02:53   

Otis wrote:

Fixed it. See attached template. Place that template in: <llblgen pro install folder>\Frameworks\NHibernate\Templates\Shared\C#\

(as administrator, if you're using vista/7)

Of course regenerate your code simple_smile

Thanks! That worked great. Thanks for the hint on typed views as well. That's my next thing to try.

Dave Erwin
User
Posts: 12
Joined: 04-Oct-2010
# Posted on: 05-Nov-2010 18:23:15   

Otis wrote:

Fixed it. See attached template. Place that template in: <llblgen pro install folder>\Frameworks\NHibernate\Templates\Shared\C#\

(as administrator, if you're using vista/7)

Of course regenerate your code simple_smile

Actually the original wasn't working for me with a relationship either. The fixed template didn't work for a relationship until I changed line 48 from

        if(typedList.EdgeCount<=1)

to

        if(typedList.EdgeCount<1)

Now it seems to work either way, not sure if that would mess anything else up, it's my first look at a template.

Thanks,

Dave Erwin

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 05-Nov-2010 19:10:23   

Dave wrote:

Otis wrote:

Fixed it. See attached template. Place that template in: <llblgen pro install folder>\Frameworks\NHibernate\Templates\Shared\C#\

(as administrator, if you're using vista/7)

Of course regenerate your code simple_smile

Actually the original wasn't working for me with a relationship either. The fixed template didn't work for a relationship until I changed line 48 from

        if(typedList.EdgeCount<=1)

to

        if(typedList.EdgeCount<1)

Now it seems to work either way, not sure if that would mess anything else up, it's my first look at a template.

Thanks,

Dave Erwin

Hmm. Strange, I had two typedlists, 1 with a relationship, 1 without. The one without failed (like yours) the one with a relationship worked. Will look into it simple_smile (will be monday though)

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 08-Nov-2010 14:27:48   

You're right, the typedlists we used for testing were more complex and had 2 or more relationships. Your fix is correct, you can keep that one.

Fixed in next build.

Frans Bouma | Lead developer LLBLGen Pro