Samina
Samina

Reputation: 31

'Default values not supported error' when working with Entity Framework Code First and SQLServer Compact 4.0

I am trying both xunit and TestDriven.Net for testing, for database using SQL CE4. Here is the entity definition:

    public class Product 
    {
        private readonly ICollection<Inventory> inventories = new List<Inventory>();
        private int id;

        public virtual int Id { get; set; }        

        //public virtual string ProductName { get; set; }

        public virtual ICollection<Inventory> Inventories 
        {
            get { return inventories; }
        }
    }

    public class ProductConfiguration : EntityTypeConfiguration<Product>
    {
        public ProductConfiguration()
        {
           HasKey(p => p.Id); //Id column of the product is an Identity column

           Property(p => p.Id);
        }
    }

And here is the test method:

    [Fact]
    public void WhenProductAddedItShouldPersist()
    {
        var product= ObjectMother.Single<Product>();
        productRepository.Add(product);
        unitOfWork.Commit();
        Assert.NotNull(productRepository.One(product.Id));
    }

XUnit passes the method while TestDriven fails with the message - 'System.NotSupportedException : Default values not supported'.

Surprisingly- if I add another property to the entity (e.g. ProductName), TestDriven also pass. Could anyone give me some clue why this is happening?

Upvotes: 3

Views: 1138

Answers (1)

Elias
Elias

Reputation: 41

I'm getting the same error and while searching I found this: http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/583c7839-22a4-460e-8665-3e5e3998a0d5

Looks like it's a known bug.

Upvotes: 4

Related Questions