I以下のモデルがあります:データベースASP.NET MVCからモデルを読み込む
namespace Factura.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
[Table("factura.marfa")]
public partial class marfa
{
[Key]
public int idmarfa { get; set; }
[StringLength(45)]
public string denumire { get; set; }
public int idfurnizor { get; set; }
}
}
をそして私はまた、DbContext継承したクラスがあります。私のコントローラで
namespace Factura.Models
{
using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
public partial class FacturaContext : DbContext
{
public FacturaContext() : base("name=FacturaContext")
{
}
public virtual DbSet<marfa> marfas { get; set; }
[...]
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
[...]
}
}
}
をI、次のコードを持っています:
namespace Factura.Controllers
{
[Authorize]
public class CumparatorController : Controller
{
FacturaContext dbFactura = new FacturaContext();
[HttpGet]
public ActionResult Cumparaturi()
{
var marfas = dbFactura.marfas.ToList();
return View(marfas);
}
}
}
私が持っている問題は、それがanythをもたらすものではありません、dbFactura.marfas
がnullであるということですテーブルにデータが入力されていても、データベースから取得できます。
誰もがこれを手伝ってくれますか? ありがとうございました!
コードが正常に見える移行&実行を作成
FacturaContext
であなたの
OnModelCreating
で次のマーファクラスから[Table("factura.marfa")]
を削除し、追加します。それが「ヌル」であることをどのように確認しましたか? – Shyjuクラッシュし、その行にブレークポイントを設定します – Cristina