asp.net mvc - How can I use nHibernate to get a small subset of object properties for list view -
I am using ASP.NET MVC and nHibernate for the first time. Great tool, but the big learning curve!
I have a list view of such items which are large (each has about 60 properties). In the list view, I'm only using these 10 properties. Performance is not very bad, but it seems wasted to completely hydrate these objects. What is the recommended exercise?
I tried to use HQL to select fewer properties, but it seems that it will not partially hydrate an object. I also tried to create an asset on the main object, which was a header class with list view properties, but I think it can not be mapped properly. I think it should be easy, but I'm really struggling with it.
Edit: I was coming back to this because I knew that Anton had given me a reply and I just could not see it.
- Make an object with the property you want.
-
Import this object to create a mapping file.
& lt;
Hibernate-mapping xmlns = "vase: nibinet-mapping -2.2" namespace = "core.nitties" assembly = "core" default-access = /& lt;
/ hibernate-mapping> & lt; import class = "request header" /& gt;
If you are using HQL, then a constructor with all the properties in your object should have a new statement in the same order as your selection. . If you use the Criteria API, you do not need to do this.
Public IList & lt; RequestHeader & gt; ListAll () (usage (eSession session = GetSession ()) ({ITRansaction tx = session.BeginTransaction ()) {IList & lt; RequestHeader & gt; Result = session Prepare calculations (typef (request), "R"). CreateArtia ("Requestor", "Rick", Joint Type.Inrzoyan). Cretecritia ("R. Grant", "Jee", Joint Type.Inrogen) .Setprojection projection. Projection List () Add (Projection Property ("RID"), "ID"). Add (Projection Property ("R. Status"), "Status"). Add (Projection Property ("R" properties ("g.Number"), "number")) .Setet Transformers (Transactions) (Projections ("req.Name"), "Requestor") Add. .AliasToBean (typeof (RequestHeader)) .SetMaxResults (10000) .List & lt; RequestHeader & gt; (); tx.Commit (); Return Results;}}}
See 60 properties are too high.
To select a subset of properties , See: you have a choose new
to build the HQL The Shykta is. Keep in mind, though, you need an appropriate constructor and objects can not be saved if you get it back dB.
Comments
Post a Comment