我们的客户交易表包含多个带外键的查找表。当 CustomerService 创建客户订单交易时,我们希望使用这些查找表创建下拉菜单。如果一个人稍后查看交易,他们会看到 4 个表连接在一起。
我会创建,
(a) 4 个接口(interface)和 4 个存储库,
(b) 或 2 个接口(interface)(1 个用于客户交易,1 个接口(interface)用于查找表),1 个存储库用于客户交易,3 个存储库用于查找表接口(interface)?
我们想将 Lookup table Repository 中继到下面的 SelectList。每个选择列表都在选择特定的列。想要高效的代码。
模型:
public class CustomerTransaction
{
public int CustomerTransactionId{ get; set; },
public int ProductTypeId {get; set; }, //joins to ProductTypeTable
public int StatusKey {get; set; }, //joins to StatusTypeTable
public int CustomerTypeId {get; set; } //joins to CustomerTypeTable
public string DateOfPurchase{ get; set; },
public string PurchaseAmount { get; set; },
}
public class ProductType
{
public int ProductTypeId{ get; set; }
public int Size { get; set; }
public int Weight { get; set; },
public string ProductName { get; set; },
public string ProductDescription { get; set; },
}
public class StatusType
{
public int StatusKey{ get; set; }
public string Description{ get; set; },
public string Symbol { get; set; },
}
public class CustomerType
{
public int KeyNumber{ get; set; },
public int Height{ get; set; }
public string HairColor{ get; set; },
public string NameOfPerson{ get; set; },
public string ResearchNotes{ get; set; },
}
下拉列表中的必填字段
ViewData["ProductTypeId"] = new SelectList(_context.ProductType, "ProductName", "ProductDescription");
ViewData["KeyNumber"] = new SelectList(_context.CustomerType , "NameofPerson", "Description");
ViewData["StatusKey"] = new SelectList(_context.StatusType, "Symbol", "ResearchNotes");
最佳答案
您可以创建一个数据传输对象 (DTO) 来满足您的前端需求。
public class EditTransaction {
CustomerTransaction customerTransaction { get; set; }
SelectList productTypes { get; set; }
SelectList statusType { get; set; }
SelectList customerTypes { get; set; }
}
包括一个类/方法/ Controller /任何访问您的 DAL 存储库并组装 DTO 的东西。您的客户端代码获取 DTO。存储库和 UI 中没有任何“特殊”内容。
关于c# - 多个查找表的 MVC 核心存储库模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50456115/