感谢 zamboni 给我的帮助编写适用于整个数据库而不是表的查询 https://stackoverflow.com/questions/46086616/write-a-query-that-applies-to-an-entire-db-instead-of-a-table
我正在使用 EF 编写一个查询,该查询从 aspNet_Users 表返回 userId。然后我使用这个ID删除会员资格、userINroles和用户中的记录...但是查询返回的userId是错误的值..并且我连接到正确的数据库iv检查了connectionString并测试了其他数据
using (DEntities Context = DAOHelper.GetObjectContext<DEntities>())
{
Guid aspUserIdToRemove = Context.ExecuteStoreQuery<string>("Select UserId FROM aspnet_Users where UserName LIKE '%" + userName + "%'").ElementType.GUID;
string aspUserId = aspUserIdToRemove.ToString();
aspUserId = aspUserId.Replace("{", string.Empty);
aspUserId = aspUserId.Replace("}", string.Empty);
Context .ExecuteStoreCommand("DELETE FROM aspnet_Membership where UserId = '" + aspUserId + "'");
Context .ExecuteStoreCommand("DELETE FROM aspnet_UsersInRoles where UserId = '" + aspUserId + "'");
Context .ExecuteStoreCommand("DELETE FROM aspnet_Users where UserId = '" + aspUserId + "'");
aspUserIdToRemove 在应该返回 {31E62355-8AE2-4C44-A270-2F185581B742} 时返回 {296afbff-1b0b-3ff5-9d6c-4e7e599f8b57}...
{296afbff-1b0b-3ff5-9d6c-4e7e599f8b57} 甚至不存在于数据库中......有人知道出了什么问题吗?谢谢
只是为了强调在同一个数据库上,我在不同的表上执行进一步的删除命令并确认它们已被删除
根据评论 -
var s = dnnEntitiesDbContext.ExecuteStoreQuery<string>("Select UserId FROM aspnet_Users where UserName LIKE '%" + userName + "%'");
s.elementtype.GUID 包含 296afbff-1b0b-3ff5-9d6c-4e7e599f8b57
但 s.base.elementType.baseType.Guid 返回一个差异 GUID '81c5f...
但没有我要找的那个人的迹象