How to map the (FluorineFX)ByteArray type to byte[

2019-07-30 08:15发布

问题:

In a new project i have to use a Flex client. This client gets data from and saves data to a ASP.NET Website.

For the communication between these two physical separated layers FluorineFX is used. The communication works fine (to or from the ASP.NET-Fluorine Service).

So the next step is to write to or read from the (SQLServerCE)DBMS. I 'm stuck with this: the service gets some objects (works fine) and tries to persist these to the store. My problem is how to translate the ByteArray DataType of FluorineFX directly to a type of EntityFramework (may be byte[]).

I want to achieve the following: for example get the objects from the client and (using POCOs) persist directly.

So would it be possible to generate the following (code first POCO) class and also persisting this class directly?

public class Photo
{
public string   GUID {get;set;}
public string   Title                 {get;set;} 
public ByteArray   Thumbnail             {get;set;}
public ByteArray   Picture               {get;set;} 
}

Is this possible through an extension to EntityFramework? or somehow else?

Thanks in advance

回答1:

public static ByteArray BytesToByteArray(byte[] bytes)
    {
        var ms1 = new MemoryStream(bytes);
        return new ByteArray(ms1);
    }

    public static byte[] ByteArrayToBytes(ByteArray byteArray)
    {
        uint length = byteArray.Length;
        byte[] bytes = new byte[length];
        byteArray.ReadBytes(bytes, 0, length);
        return bytes;
    }

Check if this helps