How to send a criteria to a DataPortal.insert
How to send a criteria to a DataPortal.insertOld forum URL: forums.lhotka.net/forums/t/8455.aspx
lastalaica posted on Tuesday, February 02, 2010Hi,
I've been using CSLA for a month now and I've been wondering if a dataportal with 2 argument exist...
I searched trough google but didn't see anything.
Does someone have an answer?
rxelizondo replied on Tuesday, February 02, 2010
What DataPortals do you speak off? Root object DataPortal calls such as DataPortal.Create, DataPortal.Fetch etc? If so the general pattern is to create a criteria object and on that criteria you can put as many parameters as you want. A good example of multy parameter criteria is the CSLA Csla.Security.UsernameCriteria object.
Child DataPortal calls such as DataPortal.CreateChild, DataPortal.FetchChild, should allow you to pass multiple parameters by desing. All you need to make sure is that your Child_Create, Child_Fetch etc methods match the parameters you are sending on the DataPortal calls.
lastalaica replied on Wednesday, February 03, 2010Yes, my object is a root one.
I created an criteria object like you mentionned and now it seems to works
I will post again if I have some trouble
lastalaica replied on Wednesday, February 03, 2010I have this error when I try to build my solution :
ProjectName.ClassName.DataPortal_Insert(Csla.Security.CustomCriteria)': no suitable method found to override
I know what it means but when I try to run my program when the override is not there, it throw this exception :
System.NotSupportedException: Invalid operation - insert not allowed
ajj3085 replied on Wednesday, February 03, 2010Your DataPortal_Insert shouldn't require any criteria objects. All the information needed should be stored in the BO via private fields or managed fields.
lastalaica replied on Wednesday, February 03, 2010I know but I don't really have choice, the criteria I send contain the "secured channel" of my application (it's a wcf service) and when I need to execute a stored procedure, I need to send the "secured channel" ...
I must configure my channel only one time in my application so when I want to do an (insert, update, delete...) I need to send the channel.
Must I really create a property in each of my object to contain the channel? I don't really like it, but if I don't have any choice...
ajj3085 replied on Wednesday, February 03, 2010
If it's something you'd need in each instance, you should probably store it in the ApplicationContext.
Use GlobalContext if the value should flow from client to server, and server to client every call.
Use ClientContext if the value should be on the client and sent to the server (but not back).
Use LocalContext if the value should stay at whatever location its at (if used on the client, the value is only available on the client. If on the server, then only on the server).
lastalaica replied on Wednesday, February 03, 2010I don't really see the use of an applicationContext...
the channel that I pass trough all my method is what I use to call my method on the server side, I don't need to send the channel to my server
ajj3085 replied on Wednesday, February 03, 2010What exactly is it that you're trying to do? It sounds like you have some information on the client that the server needs to know to execute a wcf call on the server, and this information is required anytime you're doing a data portal call.
lastalaica replied on Wednesday, February 03, 2010At the beginning of my application, I configure my windows service (client) to be able to communicate with my wcf service.
I'm using a proxy to call the method of the wcf service from the client.
Each time I want to execute one of my stored procedure, I need to do proxy.executeSP(arg1, arg2...)
but my proxy is instanciate in the main class of my windows service, so when I need to do an insert (or an update,delete...) I need to send the proxy.
If you need anything else, just ask for it
RockfordLhotka replied on Thursday, February 04, 2010
It sounds like you are not using the data portal to communicate between the client and server? You are using your own proxy?
So you are using the data portal in local mode (client-only), and your DataPortal_XZY methods are making direct WCF service calls using your own WCF proxy right?
If this is the case, and you need that proxy to be globally available to all your DataPortal_XYZ methods, then you should use one of several valid techniques to expose this as a global value. These techniques include:
- Make the proxy a singleton object
- Use Csla.ApplicationContext.LocalContext to store a reference to the proxy
- Use an IoC container (though you'd still implement the proxy as a singleton)
There are many other accepted techniques for creating a global value - see the legendary Design Patterns book (Gamma, et al) for ideas.
lastalaica replied on Friday, February 05, 2010thanks Rockford,
the problem is solved now
Copyright (c) Marimer LLC