SelfServicing Predicate Serialization

Posts   
 
    
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 15-Feb-2004 04:44:22   

I have a series of combo boxes and list boxes being used to set up search criteria. I will eventually be iterating through the selected items building a predicate expression to use on the Fill method of a typed view.

I want to be able to persist the predicate expression to persistent storage, so that the predicate expression may be used again at a later date.

Does anyone have any advice as to how I should go about doing this?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 15-Feb-2004 11:28:18   

The predicates are serializable, you could opt for serializing it to a string and store that string in the database.

See this thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=283 for a codesnippet how to serialize to string (and back). (It's with entities, but predicates are the same)

Be aware of the fact that you should use simple serialization (it's a setting on the formatter) so you avoid having the assembly version serialized into the data. Also, be aware of the fact that if the internal members of the serialized objects change, the deserializer will probably fail.

I think it's best to serialize the expression which is reflected in the form and which is used to re-build a predicate expression.

Frans Bouma | Lead developer LLBLGen Pro
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 21-Feb-2004 21:25:00   

Well, I got it working using the soap formatter. Is there a way to do it using the binary formatter?

This is the code that I am using to serialize using the soap formatter.

            Dim formatter As Soap.SoapFormatter = New Soap.SoapFormatter
            formatter.AssemblyFormat = FormatterAssemblyStyle.Simple
            Dim writeStream As New MemoryStream
            formatter.Serialize(writeStream, filter)
            Return System.Text.Encoding.UTF8.GetString(writeStream.ToArray)

I dont beleive that I need to use soap and besides the soap formatter has alot more overhead than the binary formatter.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 22-Feb-2004 11:20:10   

You can use the same code just, create a binary formatter instead of a soap formatter simple_smile

Frans Bouma | Lead developer LLBLGen Pro