1

I have created a class in order to save MyStyles into the database. While I'm doing the Migration and Update to Database I can see the PK StyleId, but I can't find the way to persist the Color Tuple.

This is the code of my class....

public class MyStyle {
    public int StyleId{ get; set; }
    (...)
    public Tuple<int, int, int> Color { get; set; }
}

Is there any way to persist the System.Tuple class?

  • 1
    I wouldn't use a Tuple at all. Either use a System.Drawing.Color object or individual properties for Red, Green and Blue (and maybe a fourth one for Alpha) – DavidG Oct 26 '14 at 21:16
  • I do agree I souldn't use it this way, but I'm having other limitations that made me consider this option. I will consider modifying the properties then save in three int. Or perhaps mapping as Darek said – Martin Introini Oct 26 '14 at 22:56

1 Answers1

1

Yes there is, but you have to provide a converter: Convert value when mapping. Considering that a Color (there is such struct in .Net Framework by the way, so you don't have to use Tuple) is using four bytes to define RGB and alpha, you should be able to store it as Int32 in the database.

Community
  • 1
  • 1
Darek
  • 4,687
  • 31
  • 47