Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Sunday, July 6, 2025 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Web Forums - SalesLogix Web Platform & Application Architect
Forum to discuss the use of the SalesLogix Web Platform, Client and Customer Portals, and the Application Architect (For version 7.2 and higher only). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix Web Platform & Application Architect | New ThreadView:  Search:  
 Author  Thread: Custom business rules, NHibernate and HQL
Alberto Chiesa
Posts: 49
 
Custom business rules, NHibernate and HQLYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 20 Oct 08 12:04 AM
Hi all,
I'm currently implementing a business rule that, given an entity full of parameters, should return a list of contacts satisfying that given parameter set.

Now, in order to do this, I do something like:

using (NHibernate.ISession session = new Sage.Platform.Orm.SessionScopeWrapper(false))
{
List resultList = (List) session.CreateQuery(@"select con from Contact con where ...")
.List();

result = (object) resultList;
}

This code works as expected, returning the fields satisfying the where clause (well, it's a bit more complicated, with joins and stuff, but you get an idea).
The problem is that this launches a query on every contact field. I just need the id, last and first name and maybe a little more.

Is there a way to query for only the requested fields and still being able to bind the result set to the datagrid?

Thanks in advance.

Alberto
[Reply][Quote]
Nick Hollis
Posts: 549
Top 10 forum poster: 549 posts
 
Re: Custom business rules, NHibernate and HQLYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 22 Oct 08 3:36 AM
Would it not just be a case of specifying the appropriate columns in your select??
ie.
List resultList = (List) session.CreateQuery(@"select contactid,lastname,firstname from Contact con where ...")

Of course I may be completely wrong


[Reply][Quote]
Alberto Chiesa
Posts: 49
 
Re: Custom business rules, NHibernate and HQLYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 22 Oct 08 3:46 AM
Thank you. Probably you're right.

What really bothers me is: if I run a query with native SQL, AFAIK I will be missing every Hibernate binding funcionality (or at least I don't know if there is a way to cast the list to a IContact collection).

The problem is that using the quickform system, you can specify the column only based on an entity interface.

So I suppose (but maybe I'm wrong!) that you can bind only IContact enumerables on a contact datagrid.

The real question is: if I compile the select clause "by myself", either via SQL or HQL, can I bind it to a quickform datagrid without rewriting the whole form?

Thank you much for the feedback.

[Reply][Quote]
Nick Hollis
Posts: 549
Top 10 forum poster: 549 posts
 
Re: Custom business rules, NHibernate and HQLYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 22 Oct 08 4:04 AM
As long as your list returns the properties in the same name as the grid columns is expect it should bind fine - personally on complex grids that I have to create I have been creating the grid in the quickform editor, then by hacking the quickformload to finish early, create a new SQLDataSource and a Page_PreLoad event to bind the grid. As long as my SQLDataSource returns the values with the same name as the column in the datagrid expects it binds correctly. I would expect it to be the same for binding to a (i)List. After all, doesn't .NET ignore your datasource and work the same way no matter what the input? Ensure your list includes an Id property, and an EntityId (I alias mine in the SQL query) as I think the grid needs these by default.

Sorry the above is a bit cloudy but I havent worked with HQL and lists so much - this is something I will start working with more as I need to get away from SQL!!
[Reply][Quote]
Alberto Chiesa
Posts: 49
 
Re: Custom business rules, NHibernate and HQLYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 22 Oct 08 4:07 AM
Thank you much.

This is the kind of hint I was needing. I will test this as soon as I can.
[Reply][Quote]
NixDev
Posts: 98
 
Re: Custom business rules, NHibernate and HQLYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 19 Apr 09 9:59 PM
Hi Alberto, did this work?

Saludos
[Reply][Quote]
Ryan Farley
Posts: 2265
slxdeveloper.com Site Administrator
Top 10 forum poster: 2265 posts
 
Re: Custom business rules, NHibernate and HQLYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 20 Apr 09 11:18 AM
Something to remember with HQL, you're basically querying objects. Not sure why you'd only want certain properties from those objects and not the object itself. I don't think it will work, but I've not tried.

If all you're wanting is a select few fields, not the objects themselves, maybe you should just use the DataService and query them directly from the database? Why go through the entity model itself at all?
[Reply][Quote]
Mark Dykun
Posts: 297
 
Re: Custom business rules, NHibernate and HQLYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 21 Apr 09 6:20 AM
You will want to do a projection list so that it can return an array of object[] values. I have not tried HQL in the way Nick metioned just object notation. Its possible that there are times that you just want a few fields back as you could in a post process step do some other kind of work such as decryption/formatting of a credit card # to expose.

Mark
[Reply][Quote]
Mark Dykun
Posts: 297
 
Re: Custom business rules, NHibernate and HQLYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 21 Apr 09 6:23 AM
also reading the first item you will have to wrap each of the resultant rows in a component view and return as a IList

regards,
Mark
[Reply][Quote]
Alberto Chiesa
Posts: 49
 
Re: Custom business rules, NHibernate and HQLYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 22 Apr 09 6:24 AM
Yes it works. Someway.
In my case I needed a way to select only a few fields: I have to query a table of 2000000 records in join with the contact table (half a million records) and make various aggregates on them (mainly sums and count distinct).

So, I had to find a way to run a query. The first solution I found (well, the first solution working) was using the hql language and compile the query.

In this case, the only real advantage you have with HQL over standard SQL is you don't have to compile the joins by yourself, which is not much. So you're probably better using standard SQL and populate an ILIST of objects. However, since I made HQL work, I did not try SQL by myself.

What I did:
create an entity named Research to store the query's parameters.
setup 1 business rule returning an Object (in fact an ILIST) running the query.

The ResearchResult class is public and injected in the CodeSnippet dll. It exposes a property for each column I have to display.

The Business Rule compiles the HQL query, runs it and fills a LIST or ResearchResults with the array returned by the query.

Having a typed array, I can bind the grid to the ResearchResult type. I had to insert every field name by hand, for each bound column.

In the end, I don't know if there is a better way to accomplish this. The fact is that, if you cannot afford to query each and every field like NHibernate does all the time, you have to circumvent a big part of the SalesLogix layers.

If you need some code, I can cut and paste some minimal sample code. ATM the full business rule has growed fairly large (around 1000 lines of code).

Bye
[Reply][Quote]
NixDev
Posts: 98
 
Re: Custom business rules, NHibernate and HQLYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 30 Apr 09 1:26 PM
Hi Alberto. I've been trying to do something similar myself, and have some doubts. I need to create a business rule that given an account and a range of dates brings some complex data from the DB. As far as I can see, business rules only allow for primitive return types (such as string, integer, etc).

1) How are you returning the List? As an object?
2) In the form where you are displaying the data, do you bind the List programmatically (in code)? If so, i imagine you cast your object to a list, right?
3) Could you expand on the "parameter" entity idea? Are you passing it as a parameter to the business rule?
4) The ResearchResult is a custom object, an entity, what?
5) What do you mean when you say that "The ResearchResult class is public and injected in the CodeSnippet dll". What do you mean when saying that you injected the code in CodeSnippet.dll?
6) What do you mean when you say that you "had to insert every field name by hand, for each bound column."?

Thanks a lot, and sorry for the amount of questions.
[Reply][Quote]
Alberto Chiesa
Posts: 49
 
Re: Custom business rules, NHibernate and HQLYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 May 09 4:23 AM
Ok, I know there is a lot of stuff working together, so I'll try to explain a little bit further:

1) Yes. The business rule is returning an Object, which, in fact is a casted List.
2) Yes again. And, yes. You can find the code to do so in this forum. If not, feel free to ask.
3) I created a "Research" entity, with his own main view. The Research properties are the parameters used for the research. So, in the manual binding method, I simply gain access to the CurrentEntity, then call CurrentEntity.DoResearch() (which is the business rule actually executing the research and returning the casted List<>).
4) It's a custom Class. It contains a property for each column I want to retrieve in the query. I populate the List in the business rule code, copying the data returned by the query into each ResearchResult object.
5) I inserted a "public class ResearchResult { ... }" into the same snippet of the business rule executing the query. Since the class it's public and it's compiled into the SnippetLibrary dll, I can access it on the c#actions on the form. Note, however, that I used only C# snippets and not the new 7.5 code snippets.
6) Because I return data in form of a List, I cannot access a full list of fields when I open the Columns Collection of the datagrid. So I made use of a little trick: the grid displaying the query result is bound to a dummy datasource. This datasource runs a second business rule returning an empty list. Because the list is empty at form load, the grid doesn't bother to bind anything and doesn't check the presence of fields.
In the columns collection of the datagrid, I inserted each bound column by hand, matching each single property of the ResearchResult class.

I hope this makes sense (at least partially).
I want to repeat myself: probably there is a much simpler way to obtain this kind of functionality, but I didn't found it. Maybe you can develop a better way to run custom queries.

Please let me know if you find some better way: I'm not quite satisfied of this solution, basically because it's not that simple to mantain...

If you have other questions, feel free to ask.
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2025 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 7/6/2025 9:26:43 PM