This is a sample of code that I use to properly instantiate a dto

        public IList<TopicDto> Get_TopicData()
        {
            ITopicView _view = base.GetView<ITopicView>();
            IList<TopicDto> retVal = null;

            m_session = SessionManager.SessionFactory.GetCurrentSession();

            ICriteria crit = m_session.CreateCriteria<Topic>();
            IList<Topic> topics = new
GenericDAOImpl<Topic>(m_session).GetByCriteria(crit);
            if (topics.Count > 0)
            {
                retVal = (from topic in topics
                          select new TopicDto
                           {
                               TopicID = topic.Id,
                               PersonID = topic.Sponsor.Id,
                               TopicName = topic.TopicName,
                               Sponsor = topic.Sponsor.FirstName + " " +
topic.Sponsor.LastName,
                               Created = topic.Created,
                               cntQuestion = topic.Questions.Count()
                           }).ToList<TopicDto>();
            }
            crit = null;
            topics = null;
            m_session = null;

            return retVal;
        }

The TopicDTO is defined in its own class of cours.

John Davidson

On Sun, Mar 13, 2011 at 6:06 PM, José F. Romaniello
<[email protected]>wrote:

> ditto.
> Who wants half object?
>
>
> 2011/3/13 John Davidson <[email protected]>
>
>> And what happens when a flush occurs? How does NHibernate know to ignore
>> these partial objects, or how does it handle them if what was partial now
>> became a full object that you do want to save.
>>
>> As mentioned above, seems to be _very_ dangerous.
>>
>> John Davidson
>>
>>
>> On Sun, Mar 13, 2011 at 4:32 PM, Vikram Nayak <[email protected]>wrote:
>>
>>> This query will return a list of Business objects, but with only the
>>>
>>> specified fields instantiated. Note that this is a powerful
>>> technique, as the presentation layer may use ordinary business classes
>>> instead of data transfer objects, without having to know the details
>>> of the querying techniques being used
>>> Vikram
>>> Make a loan, Make a difference - Kiva.org
>>>
>>>
>>>
>>> On Sun, Mar 13, 2011 at 12:28 PM, Fabio Maulo <[email protected]>wrote:
>>>
>>>> On Sun, Mar 13, 2011 at 4:08 PM, Vikram Nayak 
>>>> <[email protected]>wrote:
>>>>
>>>>> Yes, but instead of returning a object[] or a CustomDTO it would be
>>>>> nice to be able to return the root entity initialized with only the
>>>>> fields specified in the query.
>>>>>
>>>>
>>>> eh?
>>>>
>>>> --
>>>> 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.
>>>>
>>>
>>>  --
>>> 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.
>>>
>>
>>  --
>> 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.
>>
>
>  --
> 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.
>

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