3
還有就是我的分貝的簡化模型:實體框架的核心:與問題包含方法
public class Chat
{
public ICollection<ApplicationUser> Users {get; set;} //nav property - represents participants of a chat
}
public class ApplicationUser : IdentityUser // it represents a net-identity user; it does not have any references to chats
{...}
所以,在控制器的I類試圖讓聊天內容,如包含當前用戶作爲參與者:
var user = GetUser();
_context.Chats.Where(chat => chat.Users.Contains(user)).ToList();
此代碼拋出異常:
不能使用表達式的類型...... ApplicationUser爲 參數」 S型 方法的 「Microsoft.EntityFrameworkCore.Storage.ValueBuffer」「布爾 包含[ValueBuffer](System.Collections.Generic.IEnumerable`1 [Microsoft.EntityFrameworkCore.Storage.ValueBuffer], Microsoft.EntityFrameworkCore.Storage.ValueBuffer) 「
這裏有什麼問題?
請提供您的控制器代碼多一點信息。你想把它分配給什麼? –
實際的問題是你試圖比較對象('用戶')作爲一個洞。由於EF在後臺轉換爲SQL,這將失敗。沒有用於比較對象的SQL函數。最好你通過主鍵進行查找。 – Thor