0
使用EF我想從點數據庫中刪除用戶......這一切都正常工作與類似的代碼獲得來自EF查詢的編號,然後用它來刪除記錄
DbContext.ExecuteStoreCommand("DELETE FROM activeforums_Attachments where UserId = " + userId);
DbContext.ExecuteStoreCommand("DELETE FROM activeforums_Forums_Tracking where UserId = " + userId);
DbContext.ExecuteStoreCommand("DELETE FROM activeforums_Poll where UserId = " + userId);
DbContext.ExecuteStoreCommand("DELETE FROM activeforums_Poll_Results where UserId = " + userId);
我可以使用手動刪除在aspNetUserId有:
string aspNetUserId = "'21F72BCA-A51P-47DF-B57A-C31A191C61D2'";
DbContext.ExecuteStoreCommand("DELETE FROM aspnet_Membership where UserId = " + aspNetUserId);
DbContext.ExecuteStoreCommand("DELETE FROM aspnet_UsersInRoles where UserId = " + aspNetUserId);
DbContext.ExecuteStoreCommand("DELETE FROM aspnet_Users where UserId = " + aspNetUserId);
和這個作品...所以現在我需要做的是與用戶名得到每一個人aspNetUserId ...所以我試圖像
using (DEntities DbContext = DAOHelper.GetObjectContext<DEntities>())
{
var userIdToRemove = DbContext.ExecuteStoreCommand("Select FROM aspnet_Membership where UserName = " + userName);
DbContext.ExecuteStoreCommand("DELETE FROM aspnet_Membership where UserId = " + userIdToRemove.UserId);
DbContext.ExecuteStoreCommand("DELETE FROM aspnet_UsersInRoles where UserId = " + userIdToRemove.UserId);
DbContext.ExecuteStoreCommand("DELETE FROM aspnet_Users where UserId = " + userIdToRemove.UserId);
東西
是這樣的可能嗎?使用EF時設置一個變種,如果不是有其他人就如何解決這個...感謝您的任何答覆
你爲什麼要使用SQL語句時,你已經有一個漂亮的美麗的實體框架庫? –
我正在處理其他用戶創建的現有代碼,這是我在修復錯誤時遇到的問題...不要拍攝編輯器:P – John