【发布时间】:2013-07-02 23:54:36
【问题描述】:
在我的简单数据库第一个实体框架场景中,我的客户分配了价目表编号。另一方面,有一个产品表,其中有 7 个价格列对应于价目表,例如PR_1、PR_2、PR_3等
我想对一些属性进行投影。问题是属性/字段之一取决于客户的价目表编号,因此需要动态构建。因此,如果价目表编号为 2,则要使用的属性为 PR_2,依此类推。
public IList<Product> GetSalesList(int customerId)
{
Customer customer = this.customerService.Get(customerId);
var products = this.productRepository.GetAll().OrderBy(p => p.ProductCode)
.Select(p => new Product
{
Id = p.Id,
ProductCode = p.ProductCode,
Description = p.Description,
PricingTypeCode = p.PricingTypeCode,
Quantity = 0,
SalesPrice = <<PR_ + customer.PricelistNumber.ToString()>>
}).ToList();
return products;
}
我已经阅读了有关 LINQ 的信息,但我不想使用它,因为我认为这只是一个例外。
谁能指出我正确的方向或有人对此有解决方案吗?
【问题讨论】:
标签: c# entity-framework select linq-to-entities ef-database-first