Example with images

Nov 12, 2014 at 2:03 PM
Hi
Nice code !!

Could you provide a CRUD example with image types ?

Thanks!!
Dec 16, 2014 at 4:41 PM
There are a lot of good examples under the Tests folder in the source code download.

Craig
Dec 16, 2014 at 6:51 PM
Call me stupid, but can not find any example/test with image types.... looking on folders named "Entities" but only found int, string and others types...i.e.
      [Field]
        public Guid? UUID { get; set; }

        [Field]
        public int ITest { get; set; }

        [Field]
        public string Address { get; set; }

        [Field]
        public float FTest { get; set; }

        [Field]
        public double DBTest { get; set; }

        [Field(Scale = 2)]
        public decimal DETest { get; set; }

        [Field]
        public TimeSpan TS { get; set; }

        public bool Equals(TestItem other)
        {
            return this.ID == other.ID;
        }
    }

    [Entity(KeyScheme = KeyScheme.Identity)]
    public class Position : IEquatable<Position>
    {
        public Position()
        {
        }

        [Field(IsPrimaryKey = true)]
        public int positionId { get; set; }
I'm looking something like....
public image PersonalPicture {get;set}
Coordinator
Dec 16, 2014 at 11:15 PM
Not a stupid question at all. What back-end database are you wanting to use (so I can test with the same)?
Dec 17, 2014 at 12:03 AM
database would be MS SQL CE / full ms sql server 2008
Coordinator
Dec 17, 2014 at 12:38 AM
Edited Dec 17, 2014 at 12:38 AM
I just checked in a full working example app that lets you load an image from disk, store it to a database, then pull it back out and show it in a ListView. Basically the "magic" is the use of a custom field serializer for the Image field, which is really simple. Here's my class:
    [Entity]
    class DataClass
    {
        [Field]
        public string Name { get; set; }
        [Field]
        public Image Picture { get; set; }

        public byte[] Serialize(string fieldName)
        {
            // fieldName will match the property name of the Field 
            // the ORM is trying to serialize
            if (fieldName == "Picture")
            {
                using (var ms = new MemoryStream())
                {
                    this.Picture.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    return ms.ToArray();
                }
            }

            // this will never get hit in this example
            return null;
        }

        public object Deserialize(string fieldName, byte[] data)
        {
            // fieldName will match the property name of the Field 
            // the ORM is trying to deserialize
            if (fieldName == "Picture")
            {
                using (var ms = new MemoryStream(data))
                {
                    return Image.FromStream(ms);
                }
            }

            // this will never get hit in this example
            return null;
        }
    }
Dec 17, 2014 at 4:47 PM
Edited Sep 13 at 6:50 PM
Thank you, will test and report results.

Jan/5/2016

EDIT: After several tests, I gave up. Some errors and not a clear example. Going back to "regular" CRUD code.

Thanks anyway.

EDIT2: I found the issue, my mistake. Example works just fine. I'm using your ORM on Sep/2016 ! Thanks!