-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的工作和检查配置设置? –