-1
在我的數據庫中,實體框架上下文正在使用我有一個視圖。 vwReportMonths。它返回的是一組與我需要報告的表格中記錄的月份開始相對應的日期。該視圖正常工作並返回正確的日期。實體框架無法找到數據庫視圖
我創建了模型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cards
{
public class ReportMonthView
{
public DateTime CardMonth { get; set; }
}
}
我創建了一個映射類:
using Card;
using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
namespace DAL.Card.Mapping
{
class ReportMonth_Mapping : EntityTypeConfiguration<ReportMonthView>
{
public ReportMonth_Mapping()
{
ToTable("dbo.vwReportMonths");
HasKey(x => x.CardMonth);
}
}
}
我添加映射到我的OnModelCreating方法在我使用的上下文。
modelBuilder.Configurations.Add(new TrendReportMonth_Mapping());
而且我也在上下文中創建了DbSet。
public DbSet<ReportMonthView> ReportMonths { get; set; }
但是,當我試圖從我的控制器訪問接入角度,它拋出一個無效的對象名稱dbo.vwReportMonthView「
public JsonResult GetReportMonths() {
var data = _safetyContext.TrendReportMonths;
return Json(data, JsonRequestBehavior.AllowGet);
}
我缺少什麼?我以爲我昨天對EF有了一個頓悟,但顯然不是。
再次感謝您的所有幫助。
你試過ToTable(「vwReportMonths」); ? –
是的,我也嘗試了ToTable(「CardDB.dbo.vwReportMonths」)和ToTable(「CardDB.vwReportMonths」),結果相同。 –
所有其他DbSets的工作和檢查配置設置? –