c# - 可以在 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”。
我想知道这是否可能?
解决方案
推荐阅读
- azure - Databricks 笔记本硬编码
- reactjs - 有没有办法防止这个滚动事件触发?
- kotlin - 从 kotlin 中的百分比获取价值
- hololens - 在 Kiosk 模式下配置时,是否可以从 HoloLens 2 中的门户接收虚拟输入
- python - Django Form 从数据库中检索数据
- java - burp suit 中没有可用的身份验证方案
- javascript - 将 HEIC 转换为图像格式 Reactjs
- r - 每个观察具有多行的数据,其中变量填充在一些但不是其他行中
- reactjs - redux中使用typescript时,initialstate初始化相关问题
- c# - 数组:部分填充