私はそのようなことが可能であるとは確信していません。しかし、私は列名として変数を使用したい。以下は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; }
}
私はstock.cs間の1対1の関係を持っているにvariation.cs
これは機能しません。 "ColorName"は列ではないためです。色を列として定義しました。 – senjizu
次に、あなたのデータ型がどのようにレイアウトされているかを見るために、より多くのコードが必要になると思います。 –
私の質問が更新されました – senjizu