This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have a whole bunch of User Defined Functions in my database. All of these functions are scalar type. They usually receive a date and return either an Int or a Money data value. To prevent having the code for these complex calculations in two places, i.e. in a c# class, and in the database, required in the database for us in reports etc., I want to use the SQL functions from within my C# code. I have taken a look at the registering SQL Functions, but I am sure I am missing something, but cannot work out what. In my data class I created the following classes.
Then in my code to use these methods I have the following code.
But this just throws the NotImplemented exception. What am I missing? Also, I tried to drag a SQL Function onto me model, this threw an exception? Is this not supported? Finally, how do I adapt these ServeFunctionDescriptor.Register methods to adapt to the database type? i.e. in SQL Server I must include the dbo.... but in my MySQL version of the database, I would not use this? Do I have to adapt for this manually? and do a simple if... else.... and hard code the different syntax for the UDFs? Many thanks for your help. Best regards |
|
|
In calling the method like this:
You are just calling the method, which throws a NotImplementedException since thats its implementation :) Registering those functions via the ServerFunctionDescriptor allows you to use those calls inside a LINQ query where we can understand that you are actually trying to translate that into a database function call rather than having this executed as client side code, so you need to use these as part of a LINQ query, e.g.
In terms of the designer and the error you are seeing when trying to drag a function on to your model, the designer doesn't provide any support for mapping user defined functions. In terms of your question regarding the difference between SQL Server and MySQL, are you needing to have this work across both database providers e.g. some deployments may be to SQL Server, some to MySQL? If so yes you would need to use a conditional check on the data provider set on the context to determine what function name to use - if there are a few of these differences it might pay to carry around some kind of environmental configuration that helps provide resolution for names like this but a simple if/else would also work just fine :)
|
|