Sunday 15 January 2012

c# - Using QueryOver, how do I conditionally filter results based on a method argument? -


I am working for that project, I recently worked with QueryOver syntax I'm doing NHibernate, and I've hit a snag that is how I have not found any texts to solve.

I am working in this project, I have a repository system for a group of people. The repository method assigned to a project looks like this (currently non-functional Code)

  public static IEnumerable & lt; ProjectAssignment & gt; GetProjectAssignments (include Entity Project, Bulldozer Elements) {Eshan Session = Data Contains. Gate session ()) {list & lt; Project Assat & gt; Result = session .clicover & lt; Project Assetment & gt; (). Where (P => P. project ID == project id) // problem statement! And. (P = & gt; Include Altenenets ||! P.IsNentent). List (). ToList (); Return results; }}  

My ProjectAssignment class is unimportant because it is mapping, because the problem is clear on the basis of a question I had before: includeAlternates Boolean is not mapped to my Project Asset Regiment class, nor should it be; This is an argument for the function.

What am I trying to ask:

  Ask all project assignments where I want project ID and if optional assignments are included, simply assignment, otherwise only assignment Include if this is not an optional assignment and return that list to the query.  

To do this, a new-Ethernet concept for NHibernate, however, while reading some other questions, I am not very clear on two major points, lot , and has not helped in trying to find official documents, because it is written in a way that I am completely opaque:

  • Is projection is < / Em> OK? One source said, 'This is like a selection statement in SQL' and another has chosen it from a LINQ code. Selection () Call, where it is actually just making a change, these two completely are different things as far as I know, so one of those sources is wrong. has gone.
  • On the subject of my concrete coding problem - how to

Therefore, for my queries: , I asked the question To accomplish -

  • What is projection in NHibernate, of course?
  • How can I get conditional behavior as described in my pseudocode block above?
  • NHibernate will try to parse SQL that is what you include in your circumstances and Will not be able to do because it is not part of your mapping or meaningful for the parser in that context, possibly the error you are experiencing. Projection is not a new concept for NHibernate, but I do not know how they relate to your current situation.

    Your code should read something else below, where you include your status in queries or not on the basis of boolean:

      public static IEnumerable & lt; ProjectAssignment & gt; GetProjectAssignments (Intel Project Ed, BULL Adultants) {{eSession session = Data Contains .gate session ()) using {var query = session.click & lt; Project Assetment & gt; (). Where (P => P. project ID == project ID); If (international!) {Query.And (p = & gt;! P.IsAlternate); } List & lt; Project Status & gt; Results = Query.list (). ToList (); Return results; }}  

    No comments:

    Post a Comment