无效的列名实体框架

时间:2018-03-21 10:47:18

标签: entity-framework

包含外键并引用第二个表时列名无效。 我已经这样做了,但这次我找不到错误。

我按照我对另一个视图所做的方式添加了模型,控制器和视图。 是否有我忘记的东西。上次我发现了问题,但现在它仍然给出了相同的错误INVALID COLUMN NAME,尽管我在控制器中包含了相关的表。

模型

public class Afspraken
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int Afspraakid { get; set; }

    [Required(ErrorMessage = "titel")]
    [StringLength((40))]
    public String Afspraaktitel { get; set; }

    [Required(ErrorMessage = "details")]
    [StringLength((255))]
    public String Afspraakdetailomschrijving{ get; set; }

    public virtual Cities Locatieafspraak { get; set; }
    [Required]
    public int Locatieid { get; set; }

    [Required]
    public DateTime Datumafspraak { get; set; }

}

public class Cities
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public Int32 Cityid { get; set; }

    [Required(ErrorMessage = "postcode")]
    public String Postcode { get; set; }

    [Required(ErrorMessage = "city")]
    public String City { get; set; }

    public virtual Countries Landen { get; set; }
    [Required(ErrorMessage = "country")]
    public Int32 Countryid { get; set; }

}

public class AfsprakenController : Controller
{
    private ApplicationDbContext db = new ApplicationDbContext();

    private ApplicationDbContext _context;

    public AfsprakenController()
    {
        _context = new ApplicationDbContext();
    }

    protected override void Dispose(bool disposing)
    {
        _context.Dispose();
    }

    [Authorize]
    public ActionResult Index()
    {

        //return View(db.MyProfiles.ToList());

        var afspraken = _context.Afspraken.Include(e => e.Locatieafspraak).OrderBy(e => e.Datumafspraak).ToList();
        //Include(e=>e.TypeAfspraak).Include(e=>e.Locatieafspraak).
        return View(afspraken);

    }

索引视图

@using CVtje.Models
@model IEnumerable<CVtje.Models.Afspraken>

@{
    ViewBag.Title = "Index Afspraken";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>

@*<p>
    @Html.ActionLink("New", "New")
</p>*@
<table id="afspraken" class="table table-active table-hover">

        <tr>
            <th>
                Afspraaktitel
            </th>
            @*<th>
                Locatieid
            </th>*@
            <th>
                Locatieid
            </th>

        </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @item.Afspraaktitel
            </td>
            <td>
                @item.Afspraakid
            </td>
            <td>


            </td>


  </tr>
    }

</table>

0 个答案:

没有答案