首页 > 解决方案 > 可以在 UseInMemoryDatabase 中传递具有列表/数组的类吗?

问题描述

我正在使用UseInMemoryDatabase.net 创建一个哑数据库,但我无法在我试图放入内存的类中传递列表/数组。

public class Products
{
    [Key]
    public long productId { get; set; }
    public string productName { get; set; }
    public double productPrice { get; set; }
    public string productDescription { get; set; }
    public string[] category{ get; set; }

    public Products(long productId, string productName, double productPrice, string productDescription, string[] category)
    {
        this.productId = productId;
        this.productName = productName;
        this.productPrice = productPrice;
        this.productDescription = productDescription;
        this.category = category;
    }
}

然后我试图在内存中添加这个类。

services.AddDbContext<ProductContext>(opts => opts.UseInMemoryDatabase("Products"));

但是当我调用上下文和类时,出现以下错误:

System.InvalidOperationException:“没有为实体类型“产品”找到合适的构造函数。以下构造函数具有无法绑定到实体类型属性的参数:无法在“Products(long productId, string productName, double productPrice, string productDescription, string[] category)”中绑定“category”。

我想知道这是否可能?

标签: c#.net-coreentity-framework-core

解决方案


推荐阅读