associated tables using FetchMode in nHibernate
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_1_2208810.1377604382541"
------=_Part_1_2208810.1377604382541
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
You should direct this to the NHUSERS group instead; this group is for
the development of the NH project itself, rather than usage issues.
From: Sam Martin
Sent: =E2=80=8E8/=E2=80=8E27/=E2=80=8E2013 8:45 AM
To: [email protected]
Subject: [nhibernate-development] How to fetch on single level of
associated tables using FetchMode in nHibernate
I have a series of classes that are mapped to their respective database=20
objects.
In the mapping, the fetch mode is set so that associated lookups are loaded=
=20
with the parent record.
I'm now referencing some of these objects, and as such I'm obviously=20
getting the affiliated records eagerly loaded.
If possible I don't want to use lazy loading, as I'm passing these objects=
=20
from a service layer - not ideal, but I'm hoping I can deal with this at a=
=20
query level.
Take this example:
var c =3D s.CreateCriteria(typeof(Transaction))
.Add(Restrictions.Eq("Id", myId))
.SetFetchMode("Remark", FetchMode.Join)
.SetFetchMode("Category", FetchMode.Join)
.SetFetchMode("Reason", FetchMode.Join);
var t =3D c.List<Transaction>().FirstOrDefault();
Remark has many records associated with it, these are currently being=20
loaded when I run this query.
Can you modify the ICriteria to prevent the reference entities loading=20
their associations?
In this example, I only want Transction and its directly associated Remark,=
=20
Category and Reason
Thanks
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
------=_Part_1_2208810.1377604382541
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
<HTML><HEAD>
<META content=3D"text/html; charset=3Dutf-8" http-equiv=3DContent-Type></HE=
AD>
<BODY>
<DIV>
<DIV style=3D"FONT-SIZE: 11pt; FONT-FAMILY: Calibri,sans-serif">You should =
direct this to the NHUSERS group instead; this group is for the development=
of the NH project itself, rather than usage issues.</DIV></DIV>
<DIV dir=3Dltr>
<HR>
<SPAN style=3D"FONT-SIZE: 11pt; FONT-FAMILY: Calibri,sans-serif; FONT-WEIGH=
T: bold">From: </SPAN><SPAN style=3D"FONT-SIZE: 11pt; FONT-FAMILY: Calibri,=
sans-serif"><A href=3D"mailto:[email protected]">Sam Martin</A></SPAN><=
BR><SPAN style=3D"FONT-SIZE: 11pt; FONT-FAMILY: Calibri,sans-serif; FONT-WE=
IGHT: bold">Sent: </SPAN><SPAN style=3D"FONT-SIZE: 11pt; FONT-FAMILY: Calib=
ri,sans-serif">=E2=80=8E8/=E2=80=8E27/=E2=80=8E2013 8:45 AM</SPAN><BR><SPAN=
style=3D"FONT-SIZE: 11pt; FONT-FAMILY: Calibri,sans-serif; FONT-WEIGHT: bo=
ld">To: </SPAN><SPAN style=3D"FONT-SIZE: 11pt; FONT-FAMILY: Calibri,sans-se=
rif"><A href=3D"mailto:[email protected]">nhibernate-=
[email protected]</A></SPAN><BR><SPAN style=3D"FONT-SIZE: 11pt; =
FONT-FAMILY: Calibri,sans-serif; FONT-WEIGHT: bold">Subject: </SPAN><SPAN s=
tyle=3D"FONT-SIZE: 11pt; FONT-FAMILY: Calibri,sans-serif">[nhibernate-devel=
opment] How to fetch on single level of associated tables using FetchMode i=
n nHibernate</SPAN><BR><BR></DIV></BODY></HTML><div dir=3D"ltr"><p style=3D=
"font-size: 14px; clear: both; word-wrap: break-word; color: rgb(0, 0, 0); =
font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;">I have a=
series of classes that are mapped to their respective database objects.</p=
><p style=3D"font-size: 14px; clear: both; word-wrap: break-word; color: rg=
b(0, 0, 0); font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-seri=
f;">In the mapping, the fetch mode is set so that associated lookups are lo=
aded with the parent record.</p><p style=3D"font-size: 14px; clear: both; w=
ord-wrap: break-word; color: rgb(0, 0, 0); font-family: Arial, 'Liberation =
Sans', 'DejaVu Sans', sans-serif;">I'm now referencing some of these object=
s, and as such I'm obviously getting the affiliated records eagerly loaded.=
</p><p style=3D"font-size: 14px; clear: both; word-wrap: break-word; color:=
rgb(0, 0, 0); font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-s=
erif;">If possible I don't want to use lazy loading, as I'm passing these o=
bjects from a service layer - not ideal, but I'm hoping I can deal with thi=
s at a query level.</p><p style=3D"font-size: 14px; clear: both; word-wrap:=
break-word; color: rgb(0, 0, 0); font-family: Arial, 'Liberation Sans', 'D=
ejaVu Sans', sans-serif;">Take this example:</p><pre class=3D"lang-sql pret=
typrint prettyprinted" style=3D"margin-bottom: 10px; padding: 5px; font-siz=
e: 14px; background-color: rgb(238, 238, 238); font-family: Consolas, Menlo=
, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstre=
am Vera Sans Mono', 'Courier New', monospace, serif; overflow: auto; width:=
auto; max-height: 600px; color: rgb(0, 0, 0); line-height: 18px;"><code st=
yle=3D"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation =
Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monos=
pace, serif;"><span class=3D"pln" style=3D"background-color: transparent;">=
var c </span><span class=3D"pun" style=3D"background-color: transparent;">=
=3D</span><span class=3D"pln" style=3D"background-color: transparent;"> s</=
span><span class=3D"pun" style=3D"background-color: transparent;">.</span><=
span class=3D"pln" style=3D"background-color: transparent;">CreateCriteria<=
/span><span class=3D"pun" style=3D"background-color: transparent;">(</span>=
<span class=3D"pln" style=3D"background-color: transparent;">typeof</span><=
span class=3D"pun" style=3D"background-color: transparent;">(</span><span c=
lass=3D"kwd" style=3D"background-color: transparent; color: rgb(0, 0, 139);=
">Transaction</span><span class=3D"pun" style=3D"background-color: transpar=
ent;">))</span><span class=3D"pln" style=3D"background-color: transparent;"=
>
</span><span class=3D"pun" style=3D"background-colo=
r: transparent;">.</span><span class=3D"kwd" style=3D"background-color: tra=
nsparent; color: rgb(0, 0, 139);">Add</span><span class=3D"pun" style=3D"ba=
ckground-color: transparent;">(</span><span class=3D"pln" style=3D"backgrou=
nd-color: transparent;">Restrictions</span><span class=3D"pun" style=3D"bac=
kground-color: transparent;">.</span><span class=3D"pln" style=3D"backgroun=
d-color: transparent;">Eq</span><span class=3D"pun" style=3D"background-col=
or: transparent;">(</span><span class=3D"str" style=3D"background-color: tr=
ansparent; color: rgb(128, 0, 0);">"Id"</span><span class=3D"pun" style=3D"=
background-color: transparent;">,</span><span class=3D"pln" style=3D"backgr=
ound-color: transparent;"> myId</span><span class=3D"pun" style=3D"backgrou=
nd-color: transparent;">))</span><span class=3D"pln" style=3D"background-co=
lor: transparent;">
</span><span class=3D"pun" style=3D"background-colo=
r: transparent;">.</span><span class=3D"pln" style=3D"background-color: tra=
nsparent;">SetFetchMode</span><span class=3D"pun" style=3D"background-color=
: transparent;">(</span><span class=3D"str" style=3D"background-color: tran=
sparent; color: rgb(128, 0, 0);">"Remark"</span><span class=3D"pun" style=
=3D"background-color: transparent;">,</span><span class=3D"pln" style=3D"ba=
ckground-color: transparent;"> FetchMode</span><span class=3D"pun" style=3D=
"background-color: transparent;">.</span><span class=3D"kwd" style=3D"backg=
round-color: transparent; color: rgb(0, 0, 139);">Join</span><span class=3D=
"pun" style=3D"background-color: transparent;">)</span><span class=3D"pln" =
style=3D"background-color: transparent;">
</span><span class=3D"pun" style=3D"background-colo=
r: transparent;">.</span><span class=3D"pln" style=3D"background-color: tra=
nsparent;">SetFetchMode</span><span class=3D"pun" style=3D"background-color=
: transparent;">(</span><span class=3D"str" style=3D"background-color: tran=
sparent; color: rgb(128, 0, 0);">"Category"</span><span class=3D"pun" style=
=3D"background-color: transparent;">,</span><span class=3D"pln" style=3D"ba=
ckground-color: transparent;"> FetchMode</span><span class=3D"pun" style=3D=
"background-color: transparent;">.</span><span class=3D"kwd" style=3D"backg=
round-color: transparent; color: rgb(0, 0, 139);">Join</span><span class=3D=
"pun" style=3D"background-color: transparent;">)</span><span class=3D"pln" =
style=3D"background-color: transparent;">
</span><span class=3D"pun" style=3D"background-colo=
r: transparent;">.</span><span class=3D"pln" style=3D"background-color: tra=
nsparent;">SetFetchMode</span><span class=3D"pun" style=3D"background-color=
: transparent;">(</span><span class=3D"str" style=3D"background-color: tran=
sparent; color: rgb(128, 0, 0);">"Reason"</span><span class=3D"pun" style=
=3D"background-color: transparent;">,</span><span class=3D"pln" style=3D"ba=
ckground-color: transparent;"> FetchMode</span><span class=3D"pun" style=3D=
"background-color: transparent;">.</span><span class=3D"kwd" style=3D"backg=
round-color: transparent; color: rgb(0, 0, 139);">Join</span><span class=3D=
"pun" style=3D"background-color: transparent;">);</span><span class=3D"pln"=
style=3D"background-color: transparent;">
var t </span><span class=3D"pun" style=3D"background-color: transparent;">=
=3D</span><span class=3D"pln" style=3D"background-color: transparent;"> c</=
span><span class=3D"pun" style=3D"background-color: transparent;">.</span><=
span class=3D"pln" style=3D"background-color: transparent;">List</span><spa=
n class=3D"pun" style=3D"background-color: transparent;"><</span><span c=
lass=3D"kwd" style=3D"background-color: transparent; color: rgb(0, 0, 139);=
">Transaction</span><span class=3D"pun" style=3D"background-color: transpar=
ent;">>().</span><span class=3D"pln" style=3D"background-color: transpar=
ent;">FirstOrDefault</span><span class=3D"pun" style=3D"background-color: t=
ransparent;">();</span></code></pre><p style=3D"font-size: 14px; clear: bot=
h; word-wrap: break-word; color: rgb(0, 0, 0); font-family: Arial, 'Liberat=
ion Sans', 'DejaVu Sans', sans-serif;">Remark has many records associated w=
ith it, these are currently being loaded when I run this query.</p><p style=
=3D"font-size: 14px; clear: both; word-wrap: break-word; color: rgb(0, 0, 0=
); font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif;">Can y=
ou modify the ICriteria to prevent the reference entities loading their ass=
ociations?</p><p style=3D"font-size: 14px; clear: both; word-wrap: break-wo=
rd; color: rgb(0, 0, 0); font-family: Arial, 'Liberation Sans', 'DejaVu San=
s', sans-serif;">In this example, I only want Transction and its directly a=
ssociated Remark, Category and Reason</p><p style=3D"font-size: 14px; clear=
: both; word-wrap: break-word; color: rgb(0, 0, 0); font-family: Arial, 'Li=
beration Sans', 'DejaVu Sans', sans-serif;">Thanks</p></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;nhibernate-development" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].<br />
For more options, visit <a href=3D"https://groups.google.com/groups/opt_out=
">https://groups.google.com/groups/opt_out</a>.<br />
------=_Part_1_2208810.1377604382541--
--
---
You received this message because you are subscribed to the Google Groups
"nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.