我嘗試在EF核心中使用存儲過程。我的目的是從數據庫表中獲取行數,但我無法發送多個參數。我得到一個錯誤:EF核心存儲過程:在發佈多個參數時發現'沒有找到隱式類型數組的最佳類型'錯誤
No best type found for implicitly-typed array
其實我不知道如何使用Linq語法。在此先感謝
存儲過程:
create proc sp_getExistorNExistCountStd
@Date datetime2(7),
@ClassId int,
@Absent bit,
@Count int out
as
begin
select @Count = COUNT(*)
from RollCalls
where DateRollCall = @Date
and ClassId = @ClassId
and [Absent] = @Absent
return @Count
end
C#
int ExistStdCount = db.RollCalls.FromSql("sp_getExistorNExistCountStd @p0 ,@p1, @p2",
// getting error in this section
parameters: new[] {DateTime.Now.Date, classIds[i], true }).FirstOrDefault();
改爲使用'new object [] {...}'。 –
備註:您應該**不要**爲存儲過程使用'sp_'前綴。微軟已經保留了這個前綴以供自己使用(參見*命名存儲過程*)](http://msdn.microsoft.com/en-us/library/ms190669%28v=sql.105%29.aspx),以及你將來有可能冒着名字衝突的風險。 [這對你的存儲過程性能也是不利的](http://www.sqlperformance.com/2012/10/t-sql-queries/sp_prefix)。最好只是簡單地避免使用'sp_'並將其他內容用作前綴 - 或者根本沒有前綴! –