を取得するときに、私はクラスのデータベースのレコード持っているすべてのエンティティをロードしません:ASPは、データベースレコード
public class Wallet
{
public Wallet()
{
}
public Wallet(string userName, CurrencySellPrices currencySellPrices, CurrencyAmounts currencyAmounts, double availableMoney)
{
UserName = userName;
CurrencySellPrices = currencySellPrices;
CurrencyAmounts = currencyAmounts;
AvailableMoney = availableMoney;
}
public int Id { get; set; }
public string UserName { get; set; }
public CurrencySellPrices CurrencySellPrices { get; set; }
public CurrencyAmounts CurrencyAmounts { get; set; }
public double AvailableMoney { get; set; }
}
を、私はこのコードでレコードを選択しようとすると:
public ActionResult Exchange()
{
var username = User.Identity.GetUserName();
var model = _db.Wallets.ToList().Find(r=>r.UserName==username);
return View(model);
}
これは正しいレコードを取得しますが、クラスCurrenciesSellPricesおよびCurrencyAmountsのオブジェクトはnullです。データベースでは、それらは適切なレコードです。
クラスは次のようになります。
{
public int Id { get; set; }
public int UsdAmount { get; set; }
public int EurAmount { get; set; }
public int ChfAmount { get; set; }
public int RubAmount { get; set; }
public int CzkAmount { get; set; }
public int GbpAmount { get; set; }
}
public class CurrencySellPrices
{
public int Id { get; set; }
public double UsdSellPrice { get; set; }
public double EurSellPrice { get; set; }
public double ChfSellPrice { get; set; }
public double RubSellPrice { get; set; }
public double CzkSellPrice { get; set; }
public double GbpSellPrice { get; set; }
}
私は、彼らが適切にデータベースからロードされていないので、何かが私のクラスイム足りませんか?
それは、ありがとうございました。あなたの回答@OrelErakiに感謝します! – VeryVicious