Search   

Friday, February 10, 2012

Support » Support Forum

Register  Login

 Menu  
 
    

 Welcome!  
 


Welcome to the NDO support forum!

kreis.gif Please register/login at the site if you want to post a thread. We sometimes copy support mails of common interest to the forum. They appear with anonymous sender.
kreis.gif Please post your messages in English language if possible. You can do your posts also in German, we will translate your post and our answer so that all users of the forum can read your posts.
kreis.gif The forum software requires that javascript is enabled.
kreis.gif Please do not insert licence information or licence keys in forum posts.
kreis.gif If you know a good answer to a post of another user, feel free to reply!
kreis.gif The forum is monitored. We reserve the right to remove posts we consider not to be useful for other forum users.

   Print   

      
 NDO Support Forum  
 
SearchForum Home
  NDO-Forum postings in english please, if possible.  Developing with NDO  Works Query.Exe...
 Works Query.ExecuteAggregate with MS SQL Server 2005 ?
 
 9/26/2006 11:56:38 AM
lursa
3 posts


Works Query.ExecuteAggregate with MS SQL Server 2005 ?
 Modified By Mirko  on 11/9/2006 1:48:10 PM)

Hi, I try the following in C#:

PersistenceManager pm = new PersistenceManager();
Query myQuery = pm.NewQuery(typeof(myClass));
decimal test = myQuery.ExecuteAggregate(field name as string,
    Query.AggregateType.Max);

I get the error message: "Die angegebene Umwandlung ist ungültig." (Invalid Cast). Then I try:

PersistenceManager pm = new PersistenceManager();
Query myQuery = pm.NewQuery(typeof(myClass));
decimal test = myQuery.ExecuteAggregate(column name as string,
    Query.AggregateType.Max);

Then I get the error message: "Can't find mapping information for field myClass.myField", but the mapping file is available. If I try >field name as string< and >Query.AggregateType.Count< I get the correct count value. What am I doing wrong or doesn't work NDO with MS SQL Server 2005 ? Thanks.

 9/26/2006 12:17:03 PM
Mirko
109 posts
5th


Re: Works Query.ExecuteAggregate with MS SQL Server 2005 ?

Hi lursa,

it seems, as if there is no record in your database. The Max aggregate function returns a DbNull value, which cannot be converted to a decimal value. Count returns 0 in this case, which is convertible to decimal - that's why Count works. So, just add a record to your database and Max should work properly. If your business logic should work even if there are no result columns in the database, make sure to fetch the Count value before you fetch the Max value and check if it is 0.

Best Regards
Mirko

 9/26/2006 12:33:15 PM
lursa
3 posts


Re: Works Query.ExecuteAggregate with MS SQL Server 2005 ?
 Mirko wrote

Hi lursa,

it seems, as if there is no record in your database. The Max aggregate function returns a DbNull value, which cannot be converted to a decimal value. Count returns 0 in this case, which is convertible to decimal - that's why Count works. So, just add a record to your database and Max should work properly. If your business logic should work even if there are no result columns in the database, make sure to fetch the Count value before you fetch the Max value and check if it is 0.

Best Regards
Mirko

Thanks for your answer. Records were in database at every time during my tests ==> count result was 4; max result should 4 too, but it was the error message.
 9/26/2006 2:23:02 PM
lursa
3 posts


Re: Works Query.ExecuteAggregate with MS SQL Server 2005 ?
I've found the reason: I execute the aggregate-function on the base class and the function asks the database table from the base class AND the database table from the deduced class. The deduced class table was really empty.
  NDO-Forum postings in english please, if possible.  Developing with NDO  Works Query.Exe...
  SearchSearch  Forum HomeForum Home