我有一个存储过程,当我将其映射到EF时,它将返回具有可连接的数据选择,为该存储过程创建复杂类型模型。我是否可以更改此复杂类型,以获取存储过程返回的具有更多列的另一个模型类?或者它必须返回相同数量的列?将存储过程映射到EF中的复杂类型
感谢
例如,我含有S存储过程返回一个选择的客户:
CREATE PROCEDURE [dbo].[CustomersSelect]
AS
SELECT [CustomerID]
,[CompanyName]
,[ContactName]
,[ContactTitle]
,[Address]
,[City]
FROM [Northwind].[dbo].[Customers]
我导入EF和,而不是使用特定的复杂类型此存储过程,我想其映射到Customer类
public partial class Customer
{
public Customer()
{
this.Orders = new HashSet<Order>();
}
public string CustomerID { get; set; }
public string CompanyName { get; set; }
public string ContactName { get; set; }
public string ContactTitle { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
public virtual ICollection<Order> Orders { get; set; }
}
在控制器我尝试使用这个存储过程:
public ActionResult About()
{
var model = context.CustomersSelect();
return View(model);
}
当我运行这个关于()的动作,我收到此错误:
The data reader is incompatible with the specified 'EfMvc4Model.Customer'. A member of the type, 'Region', does not have a corresponding column in the data reader with the same name.
这个任何帮助吗?
谢谢
你试过了什么?你能展示一些你想要做的事情的代码吗? –
我只想知道定义的复杂类型是否与从存储过程返回的结果完全相同。 – tbag
我发送一个具体的例子 – tbag