我不知道为什么EF6不会为我的存储过程创建复杂类型。我正在使用数据库优先方法。
我在SSMS 2017中创建了一个新的存储过程。打开我的EDMX,右键单击“从数据库更新模型”,检查我的存储过程并完成。
在模型浏览器中,我看到了存储过程,但是没有创建复杂类型。然后我发现this post,并尝试从“编辑函数导入”创建复杂类型,但是当我单击“获取列信息”时,它告诉我 “ Selected存储过程或函数不返回任何列。”
当我在SSMS中运行存储过程时,它将返回我想要的数据。
这是我的存储过程
SELECT DISTINCT
r.ROId, ru.VIN, ru.Year, ru.Make, ru.Model, ru.ModelNo, ru.PlateNo, ru.Note
INTO
#ROUnits
FROM
tbl_ROUnits ru
INNER JOIN
tbl_RepairOrder r ON ru.ROUnitId = r.UnitId
INNER JOIN
tbl_ServiceItems s ON r.roid = s.roId
INNER JOIN
tbl_TechServiceItems tsi ON tsi.ServiceItemId = s.ItemId
WHERE
tsi.EmployeeId = @EmployeeID
AND s.IsActive = 1
AND tsi.IsCompleted = 0
SELECT DISTINCT
r.ROId, c.CustomerId, c.CompanyId, c.CompanyName,
c.FirstName, c.MiddleName, c.LastName, c.Suffix,
c.Phone1, c.Phone2, c.Email
INTO
#Customer
FROM
tbl_Customer c
JOIN
tbl_RepairOrder r ON r.CustomerId = c.CustomerId
JOIN
tbl_ServiceItems si ON si.ROId = r.roid
JOIN
tbl_TechServiceItems tsi ON tsi.ServiceItemId = si.ItemId
WHERE
tsi.EmployeeId = @EmployeeID
AND r.IsActive = 1
AND c.IsActive = 1
AND tsi.IsCompleted = 0
SELECT DISTINCT
r.ROId, r.RONo,
s.ItemId, s.Repair, s.Problem, s.Solution,
s.CalculatedHrs, s.ActualStartDateTime, s.IsCompleted, s.CompletedDate,
s.ActualEndDateTime, s.StatusId, s.RepairNo,
rs.ROStatusId, rs.Name, rs.IsActive, rs.Description
INTO
#ServiceItem
FROM
tbl_ServiceItems s
INNER JOIN
tbl_RepairOrder r ON s.ROId = r.ROId
INNER JOIN
tbl_TechServiceItems tsi ON tsi.ServiceItemId = s.ItemId
LEFT JOIN
tbl_ROStatus rs ON rs.ROStatusId = s.StatusId
WHERE
tsi.EmployeeId = @EmployeeID
AND s.IsActive = 1
AND tsi.IsActive = 1
AND tsi.IsCompleted = 0
AND s.IsCompleted = 0
AND r.ROStatus <> 'V'
SELECT DISTINCT
c.CustomerId, c.CompanyId, c.CompanyName,
c.FirstName, c.MiddleName, c.LastName, c.Suffix,
c.Phone1, c.Phone2, c.Email,
si.ROId, si.RONo, si.ItemId, si.Repair, si.Problem,
si.Solution, si.CalculatedHrs, si.ActualStartDateTime, si.IsCompleted,
si.CompletedDate, si.ActualEndDateTime, si.StatusId, si.RepairNo,
si.ROStatusId, si.Name, si.IsActive, si.Description
INTO
#CustomerService
FROM
#ServiceItem si
LEFT JOIN
#Customer c ON si.ROId = c.ROId
SELECT
ROStatusId, name, Description
INTO
#RoStatus
FROM
tbl_ROStatus
SELECT
cs.ROId, cs.RepairNo, cs.RONo,
(cs.FirstName + ' ' + cs.LastName) AS CustomerName,
cs.Name, cs.Repair,
ru.Make, ru.Model, cs.ItemId, cs.IsCompleted, ros.Name AS 'Status'
FROM
#CustomerService cs
LEFT JOIN
#ROUnits ru ON ru.ROId = cs.ROId
LEFT JOIN
#RoStatus ros ON ros.ROStatusId =cs.StatusId
ORDER BY
RONo
DROP TABLE #ROUnits, #Customer, #ServiceItem, #CustomerService, #RoStatus
答案 0 :(得分:0)
将所有参数设置为NULL或0或某个默认值,尝试仅使用名称EXEC YourSPName运行存储过程,看看是否可以看到列结构?如果不先解决,它将得到解决
示例代码:
CREATE PROCEDURE [dbo].[CustOrdersDetail]
@OrderID INT = 0
AS
SELECT * FROM Products P, [Order Details] Od
WHERE Od.ProductID = P.ProductID and Od.OrderID = @OrderID
GO
EXEC [dbo].[CustOrdersDetail]
答案 1 :(得分:0)
在查询开始之前使用 SET FMTONLY ON 设置并再次刷新实体模型。
在实体过程中有很多选择的复杂查询中,当使用实体框架时,我也会遇到这个问题。