Unless you are coding in binary, all of your code is a long string.

   Diego


On Thu, Jun 17, 2010 at 10:24, Reggie Pangilinan <[email protected]
> wrote:

> Yeah, HQL did the job for me. But the  string nature of hql is giving me a
> little itch so i'm just trying to find a way doing it in hql. I dont use
> LINQ2Nh that much because at its current state it has a lot of limitations.
> Well thanks anyway. I'll probably stick to hql for the moment.
>
> On Wed, Jun 16, 2010 at 11:52 PM, Diego Mijelshon 
> <[email protected]>wrote:
>
>> I don't use Criteria a lot, so I'm not sure about that restriction.
>> Have you tried with Linq or HQL? It's probably easier.
>>
>>    Diego
>>
>>
>> On Wed, Jun 16, 2010 at 10:57, Reggie Pangilinan <
>> [email protected]> wrote:
>>
>>>  I assume your PatientName class has a calculated property, but
>>>> NHibernate does not know about it.
>>>
>>>
>>> Yes Fullname is a calculated property and NHibernate doesnt know about
>>> it. But Nhibernate knows about the component. I think Nhibernate cannot do
>>> projection from a component (a class with different properties), But correct
>>> me if i am wrong. My conclusion is just based on pure observations. i tried
>>> this query
>>>
>>>                 IList<PatientListViewModel> list =
>>>                                 y.CreateCriteria<Patient>()
>>>
>>>
>>>  .SetProjection(Projections.ProjectionList()
>>>
>>>  .Add(Projections.Property("Birthdate"), "Birthdate")
>>>
>>>  .Add(Projections.Property("Doctor.Id"), "DoctorId")
>>>
>>>  .Add(Projections.Property("Gender"), "Gender")
>>>                                         .Add(Projections.Property("Id"),
>>> "PatientId")
>>>
>>>  .Add(Projections.Property("Name"), "Name")
>>>                                )
>>>
>>> .SetResultTransformer(Transformers.AliasToBean<PatientListViewModel>())
>>>                          .List<PatientListViewModel>();
>>>
>>> and it returned an error message
>>>
>>> Message: property does not map to a single column: Name
>>> Source: NHibernate
>>> StackTrace:
>>>    at
>>> NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetColumn(ICriteria
>>> criteria, String propertyName)
>>>    at NHibernate.Criterion.PropertyProjection.ToSqlString(ICriteria
>>> criteria, Int32 loc, ICriteriaQuery criteriaQuery, IDictionary`2
>>> enabledFilters)
>>>    at NHibernate.Criterion.AliasedProjection.ToSqlString(ICriteria
>>> criteria, Int32 position, ICriteriaQuery criteriaQuery, IDictionary`2
>>> enabledFilters)
>>>    at NHibernate.Criterion.ProjectionList.ToSqlString(ICriteria criteria,
>>> Int32 loc, ICriteriaQuery criteriaQuery, IDictionary`2 enabledFilters)
>>>    at
>>> NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetSelect(IDictionary`2
>>> enabledFilters)
>>>    at
>>> NHibernate.Loader.Criteria.CriteriaJoinWalker..ctor(IOuterJoinLoadable
>>> persister, CriteriaQueryTranslator translator, ISessionFactoryImplementor
>>> factory, ICriteria criteria, String rootEntityName, IDictionary`2
>>> enabledFilters)
>>>    at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable
>>> persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria,
>>> String rootEntityName, IDictionary`2 enabledFilters)
>>>    at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList
>>> results)
>>>    at NHibernate.Impl.CriteriaImpl.List(IList results)
>>>    at NHibernate.Impl.CriteriaImpl.List[T]()
>>>
>>>
>>> i guess you can only do projections on properties mapped to a column and
>>> not properties mapped on a component(a class with different properties).  So
>>> to provide more details here are my classes
>>>
>>>     public class PatientListViewModel
>>>     {
>>>         #region Properties
>>>         public DateTime Birthdate { get; set; }
>>>         public long DoctorId { get; set; }
>>>         public PersonName Name { get; set; }
>>>         public Gender Gender { get; set; }
>>>         public long PatientId { get; set; }
>>>         #endregion
>>>     }
>>>
>>>
>>>     public class PersonName
>>>     {
>>>         #region Fields
>>>         private string _Firstname;
>>>         private string _Lastname;
>>>         private string _Middlename;
>>>         #endregion
>>>
>>>         #region Properties
>>>
>>>         /// <summary>
>>>         /// Gets or sets the firstname.
>>>         /// </summary>
>>>         /// <value>The firstname.</value>
>>>         public string Firstname
>>>         {
>>>             get { return _Firstname; }
>>>             set
>>>             {
>>>                 _Firstname = value;
>>>             }
>>>         }
>>>
>>>         /// <summary>
>>>         /// Gets the fullname1.
>>>         /// </summary>
>>>         /// <value>The fullname1.</value>
>>>         public string Fullname1 { get { return _Lastname + ", " +
>>> _Firstname + " " + _Middlename; } }
>>>
>>>         /// <summary>
>>>         /// Gets the fullname2.
>>>         /// </summary>
>>>         /// <value>The fullname2.</value>
>>>         // public string Fullname2 { get { return _Lastname + ", " +
>>> _Firstname + " " + (_Middlename.Trim().Length > 0 ? _Middlename.Substring(0,
>>> 1) + "." : string.Empty); } }
>>>
>>>         /// <summary>
>>>         /// Gets the fullname.
>>>         /// </summary>
>>>         /// <value>The fullname.</value>
>>>         public string Fullname { get { return _Firstname + " " +
>>> _Middlename + " " + _Lastname; } }
>>>
>>>         /// <summary>
>>>         /// Gets or sets the lastname.
>>>         /// </summary>
>>>         /// <value>The lastname.</value>
>>>         public string Lastname
>>>         {
>>>             get { return _Lastname; }
>>>             set
>>>             {
>>>                 _Lastname = value;
>>>             }
>>>         }
>>>
>>>         /// <summary>
>>>         /// Gets or sets the middlename.
>>>         /// </summary>
>>>         /// <value>The middlename.</value>
>>>         public string Middlename
>>>         {
>>>             get { return _Middlename; }
>>>             set
>>>             {
>>>                 _Middlename = value;
>>>             }
>>>         }
>>>         #endregion
>>>     }
>>>
>>>
>>>
>>> On Tue, Jun 15, 2010 at 11:05 PM, Diego Mijelshon <
>>> [email protected]> wrote:
>>>
>>>> Sorry, I wasn't looking clearly.
>>>> There is NO FullName property in your mapping.
>>>> I assume your PatientName class has a calculated property, but
>>>> NHibernate does not know about it.
>>>> It's probably better to add a Name property to PatientListViewModel and
>>>> project or set Fullname from it (if you want to use the transformer, that
>>>> is)
>>>>
>>>>    Diego
>>>>
>>>>
>>>> On Tue, Jun 15, 2010 at 11:40, Reggie Pangilinan <
>>>> [email protected]> wrote:
>>>>
>>>>> Yeah i did that already here is my query
>>>>>
>>>>>             IList<PatientListViewModel> list =
>>>>>
>>>>> _patientDao.ContextSession.CreateCriteria<Patient>()
>>>>>
>>>>> .SetProjection(Projections.ProjectionList()
>>>>>
>>>>> .Add(Projections.Property("Birthdate"),
>>>>> "Birthdate")
>>>>>
>>>>> .Add(Projections.Property("Doctor.Id"),
>>>>> "DoctorId")
>>>>>
>>>>> .Add(Projections.Property("Gender"),
>>>>> "Gender")
>>>>>
>>>>> .Add(Projections.Property("Id"),
>>>>> "PatientId")
>>>>>
>>>>> .Add(Projections.Property("Name.Fullname"),
>>>>> "Fullname")
>>>>>                               )
>>>>>
>>>>>  .SetResultTransformer(Transformers.AliasToBean<PatientListViewModel>())
>>>>>                         .List<PatientListViewModel>();
>>>>>
>>>>>
>>>>> but its throwing an exception the message is "could not resolve
>>>>> property: Name.Fullname of: OneCare.Domain.Entities.Patient"
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Jun 15, 2010 at 10:25 PM, Diego Mijelshon <
>>>>> [email protected]> wrote:
>>>>>
>>>>>> Use Name.FullName instead of Patient.Name.FullName.
>>>>>> Patient does not have a Patient property.
>>>>>>
>>>>>>    Diego
>>>>>>
>>>>>>
>>>>>> On Tue, Jun 15, 2010 at 11:22, Reggie Pangilinan <
>>>>>> [email protected]> wrote:
>>>>>>
>>>>>>> This is my full mapping file for Patient Entity
>>>>>>>
>>>>>>>
>>>>>>> <?xml version="1.0" encoding="utf-8" ?>
>>>>>>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
>>>>>>>    assembly="OneCare.Domain"
>>>>>>>    namespace="OneCare.Domain.Entities">
>>>>>>>   <class name="Patient">
>>>>>>>     <id name="Id" type="Int64">
>>>>>>>       <generator class="hilo"/>
>>>>>>>     </id>
>>>>>>>     <version name="RecordVersion" column="RecordVersion"
>>>>>>> type="int"/>
>>>>>>>     <component name="Name"
>>>>>>> class="OneCare.Domain.Entities.PersonName,OneCare.Domain" >
>>>>>>>       <property name="Firstname" not-null="true"/>
>>>>>>>       <property name="Lastname"  not-null ="true"/>
>>>>>>>       <property name="Middlename"/>
>>>>>>>     </component>
>>>>>>>     <property  name ="Gender"    type
>>>>>>> ="OneCare.Domain.Entities.Gender,OneCare.Domain" />
>>>>>>>     <property  name ="Birthdate" type ="System.DateTime"
>>>>>>> not-null="true"/>
>>>>>>>     <many-to-one name="Doctor" column="DoctorId" />
>>>>>>>   </class>
>>>>>>> </hibernate-mapping>
>>>>>>>
>>>>>>>
>>>>>>> i achieved what i want using this HQL query
>>>>>>>
>>>>>>>             IList<PatientListViewModel> list =
>>>>>>>
>>>>>>> _patientDao.ContextSession.CreateQuery(@"
>>>>>>>                                                      select
>>>>>>>
>>>>>>>  f.Birthdate         as Birthdate,
>>>>>>>
>>>>>>> f.Doctor.Id         as DoctorId,
>>>>>>>
>>>>>>>  f.Gender            as Gender,
>>>>>>>
>>>>>>>  f.Id                as PatientId,
>>>>>>>
>>>>>>>  f.Name              as Name
>>>>>>>
>>>>>>>                                                      from Patient f
>>>>>>>                                                      where
>>>>>>> f.Doctor.Id = :userid
>>>>>>>                                              ")
>>>>>>>
>>>>>>> .SetInt64(@"userid",WebUserHelper.CurrentUserId)
>>>>>>>
>>>>>>> .SetResultTransformer(NHibernate.Transform.Transformers.AliasToBean<PatientListViewModel>())
>>>>>>>                          .List<PatientListViewModel>();
>>>>>>>
>>>>>>> Now i want to know if i can do this using the CRITERIA API, i heard
>>>>>>> that there are limitations using the criteria api. so is it possible to
>>>>>>> achive this kind of result? Thanks in advance.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Jun 14, 2010 at 10:34 PM, Jason Dentler <
>>>>>>> [email protected]> wrote:
>>>>>>>
>>>>>>>> What is your mapping for Patient and Name ?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Jason
>>>>>>>>
>>>>>>>>
>>>>>>>> On Mon, Jun 14, 2010 at 12:04 AM, reggieboy <
>>>>>>>> [email protected]> wrote:
>>>>>>>>
>>>>>>>>> Hello guys im trying to hydrate a DTO using projections in
>>>>>>>>> NHibernate
>>>>>>>>> this is my code
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> IList<PatientListViewModel> list =
>>>>>>>>>
>>>>>>>>> y.CreateCriteria<Patient>()
>>>>>>>>>
>>>>>>>>>  .SetProjection(Projections.ProjectionList()
>>>>>>>>>
>>>>>>>>>  .Add(Projections.Property("Birthdate"),
>>>>>>>>> "Birthdate")
>>>>>>>>>
>>>>>>>>>  .Add(Projections.Property("Doctor.Id"),
>>>>>>>>> "DoctorId")
>>>>>>>>>
>>>>>>>>>  .Add(Projections.Property("Gender"),
>>>>>>>>> "Gender")
>>>>>>>>>
>>>>>>>>>  .Add(Projections.Property("Id"),
>>>>>>>>> "PatientId")
>>>>>>>>>
>>>>>>>>>  .Add(Projections.Property("Patient.Name.Fullname"),
>>>>>>>>> "Fullname")
>>>>>>>>>                               )
>>>>>>>>>
>>>>>>>>> .SetResultTransformer(Transformers.AliasToBean<PatientListViewModel>())
>>>>>>>>>                         .List<PatientListViewModel>();
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> But this is throwing and exception, what do you think seems to be
>>>>>>>>> the
>>>>>>>>> problem? is this a limitation of the CRITERIA API?
>>>>>>>>>
>>>>>>>>> here is the error message
>>>>>>>>>
>>>>>>>>> Message: could not resolve property: Patient.Name.Fullname of:
>>>>>>>>> OneCare.Domain.Entities.Patient
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> 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]<nhusers%[email protected]>
>>>>>>>>> .
>>>>>>>>> For more options, visit this group at
>>>>>>>>> http://groups.google.com/group/nhusers?hl=en.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>  --
>>>>>>>> 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]<nhusers%[email protected]>
>>>>>>>> .
>>>>>>>> For more options, visit this group at
>>>>>>>> http://groups.google.com/group/nhusers?hl=en.
>>>>>>>>
>>>>>>>
>>>>>>>  --
>>>>>>> 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]<nhusers%[email protected]>
>>>>>>> .
>>>>>>> For more options, visit this group at
>>>>>>> http://groups.google.com/group/nhusers?hl=en.
>>>>>>>
>>>>>>
>>>>>>  --
>>>>>> 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]<nhusers%[email protected]>
>>>>>> .
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/nhusers?hl=en.
>>>>>>
>>>>>
>>>>>  --
>>>>> 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]<nhusers%[email protected]>
>>>>> .
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/nhusers?hl=en.
>>>>>
>>>>
>>>>  --
>>>> 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]<nhusers%[email protected]>
>>>> .
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/nhusers?hl=en.
>>>>
>>>
>>>  --
>>> 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]<nhusers%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/nhusers?hl=en.
>>>
>>
>>  --
>> 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]<nhusers%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/nhusers?hl=en.
>>
>
>  --
> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>

-- 
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