我不确定这种事情是否可能。但我想使用一个变量作为列名。如何在asp.net中使用字符串变量作为列名mvc
下面是我必须用
cartall.CartItems = cartdatas.Select(a => new Models.DTO.CartDTO.CartVM()
{
VariationId = a.VariationId,
ColorName = a.ColorName,
StockInfo = rpstock.FirstOrDefault(x => x.Id == a.VariationId).Yellow
}).ToList();
代码,但我想用它象下面。
我想使用的代码:
cartall.CartItems = cartdatas.Select(a => new Models.DTO.CartDTO.CartVM()
{
VariationId = a.VariationId,
ColorName = a.ColorName,
StockInfo = rpstock.FirstOrDefault(x => x.Id == a.VariationId).(a.ColorName)
}).ToList();
我Stock.cs
public class Stock:Base.BaseEntity
{
public int Id { get; set; }
public int? Yellow { get; set; }
public int? Red { get; set; }
public int? White { get; set; }
public virtual VariationEntity.Variation Variation { get; set; }
}
我Variation.cs
public class Variation : Base.BaseEntity
{
public int Id { get; set; }
public int OwnerProductID { get; set; }
public string SKU { get; set; }
public short? Height { get; set; }
public short? Width { get; set; }
public decimal? Price { get; set; }
public string Delivery { get; set; }
public int? OrderLimit { get; set; }
public virtual StockEntity.Stock Stock { get; set; }
}
我有1到1 stock.cs关系和变异.sd
这不起作用。因为“ColorName”不是列。我将颜色定义为列。 – senjizu
然后我想我需要更多的代码来看看你的数据类型是如何布局的。 –
我更新了我的问题 – senjizu