无法在添加视图时检索元数据

时间:2016-07-17 03:40:01

标签: c# asp.net-mvc

我正在尝试使用详细信息模板添加 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=&quot;data source=localhost;initial catalog=JaldiSe;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;"
  providerName="System.Data.EntityClient"/>

提供者节点:

  <providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>

1 个答案:

答案 0 :(得分:0)

我认为您需要在web.config中更改connectionStrings。 (见this帖子)