无法在添加视图时检索元数据
本文关键字:检索 元数据 视图 添加 | 更新日期: 2023-09-27 17:57:11
我正在尝试添加一个 GenerateInvoice 视图,带有一个详细信息模板,具有模型类:发票,数据上下文类:JaldiSeEntities.自动生成不会执行。
出现此错误
运行所选代码生成器时出错:"无法检索"WebUI.Models.Invoice "的元数据
控制器:
public ActionResult GenerateInvoice(int? id)
{
var prQuery = (from p in db.tbl_Invoice
join prI in db.tbl_InvoiceItem on p.Id equals prI.InvoiceId
where p.Id == id
select new Invoice() //<---This is the change here
{
Id = p.Id,
OrderId = (int)p.OrderId,
InvoiceNumber = (long)p.InvoiceNumber,
InvoiceDescription = p.InvoiceDescription,
InvoicePrice = (decimal)p.InvoicePrice,
DiscountPercentage = p.DiscountPercentage,
InvoiceStatus = p.InvoiceStatus,
ItemDescription = prI.ItemDescription,
ItemAmount = (decimal)prI.ItemAmount
});
return View(prQuery);
}
发票模式:
namespace JS.WebUI.Models
{
public class Invoice
{
public int Id { get; set; }
public Nullable<int> OrderId { get; set; }
public Nullable<long> InvoiceNumber { get; set; }
public string InvoiceDescription { get; set; }
public Nullable<decimal> InvoicePrice { get; set; }
public string DiscountPercentage { get; set; }
public string InvoiceStatus { get; set; }
public string ItemDescription { get; set; }
public Nullable<decimal> ItemAmount { get; set; }
}
}
连接字符串:
<connectionStrings>
<add name=" JaldiSeEntities"connectionString="metadata=res://*/Models.JSModel.csdl|res://*/Models.JSModel.ssdl|res://*/Models.JSModel.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=JaldiSe;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient"/>
提供程序节点:
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
我认为您需要更改连接字符串web.config
.(见这篇文章)