Transformers.AliasToEntityMap

592 views
Skip to first unread message

codemonkey

unread,
Oct 16, 2008, 7:48:18 AM10/16/08
to nhusers
Hello,

Can someone put up a quick explination of how this is being acheived
and what exactly it is doing?


Thanks

Stefan Sedich

unread,
Oct 16, 2008, 8:07:33 AM10/16/08
to nhusers
Ignore me today, it is blatantly obvious ALIAS to ENTITY MAP, mapping
an alias to entity in a dictionary, silly me.


Cheers
Stefan

--
Stefan Sedich
Software Developer
http://weblogs.asp.net/stefansedich

Stefan Sedich

unread,
Oct 16, 2008, 8:33:42 AM10/16/08
to nhusers
Now a real question on this say I have the following:

var people = session.CreateCriteria(typeof (Person))
.CreateCriteria("Orders", "o", JoinType.LeftOuterJoin)
.SetResultTransformer(Transformers.AliasToEntityMap)
.List<IDictionary>();

I can loop over to get my person and order and add to a class
PersonAndOrder, but is there a way to have it return
a List<PersonAndOrder> directly and easily without a loop?

foreach(IDictionary map in people) {
var p = new PersonAndOrder {
Person =
map[CriteriaUtil.RootAlias] as Person,
Order = map["o"] as
Model.Order
};
peopleAndOrder.Add(p);
}


Yes doing this is dumb but my current test harness project has person
and order mapped and I use this harness for all testing :) so the
example might not be logical or make sense but the idea is there.


Thanks

On Thu, Oct 16, 2008 at 8:48 PM, codemonkey <stefan...@gmail.com> wrote:
>

--

Gustavo Ringel

unread,
Oct 16, 2008, 8:39:36 AM10/16/08
to nhu...@googlegroups.com
You can set the projection to Person and Order and use AliasToBean(typeof(PersonAndOrder))...and then List<PersonAndOrder> and so you are done.

Gustavo.

Stefan Sedich

unread,
Oct 16, 2008, 8:43:51 AM10/16/08
to nhu...@googlegroups.com
Nice didn't realise I could do this:

var people = session.CreateCriteria(typeof (Person), "Person")
.CreateCriteria("Orders", "Order", JoinType.LeftOuterJoin)
.SetResultTransformer(Transformers.AliasToEntityMap)

.SetResultTransformer(Transformers.AliasToBean(typeof(PersonAndOrder)))
.List<PersonAndOrder>();

Works a charm.

Cheers

Stefan Sedich

unread,
Oct 16, 2008, 8:47:28 AM10/16/08
to nhu...@googlegroups.com
Final time I need sleep today heh don't need both transformers :

var people = session.CreateCriteria(typeof (Person), "Person")
.CreateCriteria("Orders", "Order",
JoinType.LeftOuterJoin)

.SetResultTransformer(Transformers.AliasToBean(typeof(PersonAndOrder)))
.List<PersonAndOrder>();

Case Closed....

Gustavo Ringel

unread,
Oct 16, 2008, 8:48:47 AM10/16/08
to nhu...@googlegroups.com
This is what i meant. I'm glad it worked for you.

Gustavo.
Reply all
Reply to author
Forward
0 new messages