You can use another cooked method
TypeFactory.HeuristicType(propertyInfo.PropertyType.FullName)

2009/9/14 Wayne Douglas <[email protected]>

>
> OK
>
> So I added these two methods:
>
> <code>
>
>  private ISQLQuery AddScalarValues(ISQLQuery query, Type type)
>        {
>            var info = type.GetProperties();
>
>            foreach (var propertyInfo in info)
>            {
>                query.AddScalar(propertyInfo.Name, GetType(propertyInfo));
>            }
>
>            return query;
>        }
>
>        private NHibernate.Type.IType GetType(PropertyInfo propertyInfo)
>        {
>            switch (propertyInfo.PropertyType.FullName)
>            {
>                case "System.String":
>                    return NHibernateUtil.String;
>                case "System.Decimal":
>                    return NHibernateUtil.Decimal;
>                case "System.Int32":
>                    return NHibernateUtil.Int32;
>                case "System.Guid":
>                    return NHibernateUtil.Guid;
>            }
>
>            return null;
>        }
>
> </code>
>
>
> And now it works fine!!
>
> woohoo
>
> thanks :)
>
>
>
>
> On Mon, Sep 14, 2009 at 3:53 PM, Fabio Maulo <[email protected]> wrote:
> > with SQL yes, with HQL or Criteria you can do the same without
> AddScalar...
> > why ?
> > because HQL and Criteria are OO and when you specify a property NH can
> know
> > which is the type expected.
> > NH need to know what you are going to retrieve...
> >
> >
> > 2009/9/14 Wayne Douglas <[email protected]>
> >>
> >> Hi
> >>
> >> I'm trying to get a list of unmanaged entities through calling an SP
> >> through NHibernate.
> >>
> >> from 15.1.5. Returning non-managed entities in the docs - I should
> >> just be able to:
> >>
> >> <code>
> >>
> >> sess.CreateSQLQuery("SELECT NAME, BIRTHDATE FROM CATS")
> >>        .SetResultTransformer(Transformers.AliasToBean(typeof(CatDTO)))
> >>
> >> </code>
> >>
> >> here's the actual code I'm trying to get working - this is a minimal
> >> complexity example:
> >>
> >> <code>
> >>
> >>  string sql =
> >>               "SELECT CurrentMonthBudget, Commitment FROM dbo.Balance";
> >>            IList<BudgetManager> x = Session.Session
> >>                .CreateSQLQuery(sql)
> >>
> >>
> >>
> .SetResultTransformer(Transformers.AliasToBean(typeof(BudgetManager))).List<BudgetManager>();
> >>
> >> </code>
> >>
> >> which doesn't even nearly work :(
> >>
> >> After doing some reading/googling I managed to find that I might
> >> supposed to be doing this:
> >>
> >> <code>
> >>
> >>  string sql =
> >>               "SELECT CurrentMonthBudget, Commitment FROM dbo.Balance";
> >>            IList<BudgetManager> x = Session.Session
> >>                .CreateSQLQuery(sql)
> >>                .AddScalar("CurrentMonthBudget",
> >> NHibernate.NHibernateUtil.Decimal)
> >>                .AddScalar("Commitment",
> NHibernate.NHibernateUtil.Decimal)
> >>
> >>
> >>
> .SetResultTransformer(Transformers.AliasToBean(typeof(BudgetManager))).List<BudgetManager>();
> >>
> >> </code>
> >>
> >> Is the AddScalar necessary for every return column?
> >>
> >> The names on my entity are the same as the column names being returned
> >> - it kinda hints from the example in the docs that this is all infered
> >> and AddScalar is only needed if the names are different.
> >>
> >>
> >>
> >> Cheers,
> >>
> >> w://
> >>
> >>
> >
> >
> >
> > --
> > Fabio Maulo
> >
> > >
> >
>
>
>
> --
> Cheers,
>
> w://
>
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to