I have a class that looks like this:
[Table("Coupons")]
public class Coupon
{
[Column("VET_ID")]
public string VetId { get; set; }
[Key]
public int CouponId { get; set; }
public string Name { get; set; }
public string ImageName { get; set; }
public string Text { get; set; }
[Column("ImageAlignment")]
public ImgAlignment Alignment { get; set; }
public enum ImgAlignment { TopLeft = 0, TopRight = 1, BottomLeft = 2, BottomRight = 3 };
/* public ImgAlignment Alignment
{
get { return (ImgAlignment) ImageAlignment; }
set
{ ImageAlignment = (int) value; }
}
*/
public string Html { get; set; }
}
The commented out bit is where I tried to use an enum property that mapped to an int in the DB, without expecting it to automagically work. Trouble is, this code:
Coupon newCoupon = new Coupon
{
Text = coupon,
Name = couponName,
VetId = data.VetId,
ImageName = string.Empty,
Alignment = Coupon.ImgAlignment.TopRight,
Html = string.Empty
};
db.Coupons.Add(newCoupon);
db.SaveChanges();
always throws an exception that the column 'ImageAlignment' cannot be null. But the object I am passing in, has a value for this property, I am setting it, the Alignment property should map to that column, right ?