mercredi 8 juillet 2015

Simple approach to storing and retrieving a non human readable object into SQL Server?

I am using MVC3, ASP.NET 4.5, C#, EF6.1.1 and SQL Azure and SQL Server 2008 locally.

I am looking for a simple way to store a .NET type to a generic column, so binary is fine, and then retrieve it. When retrieving it I will know how to retrieve it ie as "Object", "String" or "Int32".

To save, I believe I need:

String -> Binary
Int32 -> Binary
Object -> Binary

To retrieve, I need:

Binary -> String via String Retrieve Method.
Binary -> Int32 via Int32 Retrieve Method.
Binary -> Object via Object Retrieve Method.

I have read much on serializing and deserializing, to and from the database, using something like JSON.NET. However I think I can keep things even more simple as this data is temporary and does not need to be human readable. The application as such needs to be able to retrieve it and then convert it to String, Int32 or Object.

Some guidance on this would be appreciated, and a code example would be even better.

Thanks.

EDIT

This is my best starting point, see "Answer" in ADO.NET Object Save Approach. However I do not understand how one would retrieve this data.

Aucun commentaire:

Enregistrer un commentaire