我有一個調用的數據庫中存在的實體框架 - 從數據庫中第一個存儲過程返回GUID
public Guid GetUserID(string userName)
{
using (var entities = new entities())
{
return Guid.Parse(entities.Database.SqlQuery<Guid>(
"dbo.[GetUserID] @UserName",
new Object[] { new SqlParameter("@UserName",
userName)
}).ToString());
}
}
而且我的存儲過程的存儲過程的方法:
CREATE PROCEDURE [dbo].[GetUserID]
@UserName NVARCHAR(100)
AS
BEGIN
SET NOCOUNT ON;
SELECT TOP 1 ID FROM [DBO].[USER] WHERE USERNAME = @UserName
ORDER BY CREATEDON DESC
END
GO
我加了一些日誌並得到以下錯誤:
Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
at System.Guid.TryParseGuidWithNoStyle(String guidString, GuidResult& result)
at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result)
at System.Guid.Parse(String input)
什麼導致上述錯誤?
謝謝了。這解決了我的問題。從昨天打破我的頭腦,找出真正的問題是什麼。 – Yoda