I am really really new to ASP.NET and I am dealing with a problem here. The problem is pretty much obvious in the title and I'm trying to solve it. Here is one of the list members I'm trying to add in the database:
new Product
{
Name = "Sleep Suit",
Description="For sleeping or general wear",
Price=4.99m,
CategoryID=categories.Single( c => c.Name == "Clothes").ID
}
This is the product class in the models folder:
public partial class Product
{
public int ID { get; set; }
[Required(ErrorMessage = "The product name cannot be blank.")]
[StringLength(50, MinimumLength = 3, ErrorMessage = "Please enter a product name between 3 and 50 characters in length.")]
[RegularExpression(@"^[a-zA-Z0-9'-'\s]*$", ErrorMessage = "Please enter a product name made up of letters and numbers only.")]
public string Name { get; set; }
[Required(ErrorMessage = "The product description cannot be blank.")]
[StringLength(200, MinimumLength = 10, ErrorMessage = "Please enter a product description between 10 and 200 characters in length.")]
[RegularExpression(@"^[,;a-zA-Z0-9'-'\s]*$", ErrorMessage = "Please enter a product description made up of letters and numbers only.")]
[DataType(DataType.MultilineText)]
public string Description { get; set; }
[Required(ErrorMessage = "The price cannot be blank.")]
[Range(0.10, 10000, ErrorMessage = "Please enter a price between 0.10 and 10000.00")]
[DataType(DataType.Currency)]
[DisplayFormat(DataFormatString = "{0:c}")]
[RegularExpression("^[0-9]+(\\.[0-9][0-9])?$", ErrorMessage = "The price must be a number up to two decimal places")]
public decimal Price { get; set; }
public int? CategoryID { get; set; }
public virtual Category Category { get; set; }
public virtual ICollection<ProductImageMapping> ProductImageMappings { get; set; }
}
When I try to run the seed method with "Update-Database" in the Package Manager Console, I'm getting this error.
System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
And, this is the detail:
BabyStore.Models.Product failed validation - Price : The price must be a number up to two decimal places
Apparently it fails while checking the regex expression of "Price" but i don't really enter something that will fail this expression. As you see, the price is declared as "4.99m" which has 2 decimal places. What should I do to fix this? I'm Turkish so we're using comma instead of dot while seperating decimal places, so it might be the issue but i don't really know.
Any opinion is appreciated, thanks.