开发者

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

开发者 https://www.devze.com 2023-03-19 16:46 出处:网络
I am trying both xunit and TestDriven.Net for testing, for database using SQL CE4. Here is the entity definition:

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.NotSupportedExce开发者_JS百科ption : 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号