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].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to