English 中文(简体)
NHibernate: How to fetch an object without its child collections?
原标题:

My objects of type Object1 contain List Children1 property. I would love to get these objects without children.

Seems like detachedCriteria.SetFetchMode ("Children1", FetchMode.Lazy) should be the thing, but apparently it s not :( I tried getting the data in using (new SessionScope()) and setting null to .Children1 but it didn t succeed (the data was already fetched).

Any ideas would be appreciated.

问题回答

When you map the collection, are you specifying not to use lazy loading? Try specifying lazy loading at this point.

We had the same problem in our current solution and setting Lazy in the mapping didn t work. We had to set default-lazy to true and suddenly it worked.

This would work best if all relations should be lazy by default.

When using the ICriteria API to retrieve your entities, you can specify (override) the fetchmode that has to be used for the associations:

ICriteria crit = session.CreateCriteria (typeof(MyEntity));
crit.SetFetchMode ("someAssociationPath", FetchMode.Lazy);

It seems to me that you are using one-to-one mapping. In this case lazy loading will not work by design. If it s so please check this article. Otherwise please provide a bit more code and mappings.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签