C# 如何删除ASP.NET Identity中与其他实体具有可选关系的用户
我正在创建一个MVC5应用程序,并使用Identity Framework进行身份验证。IdentityUser与内容实体具有一对多的可选关系:C# 如何删除ASP.NET Identity中与其他实体具有可选关系的用户,c#,asp.net-mvc,entity-framework,asp.net-identity,C#,Asp.net Mvc,Entity Framework,Asp.net Identity,我正在创建一个MVC5应用程序,并使用Identity Framework进行身份验证。IdentityUser与内容实体具有一对多的可选关系: public class Content { public int Id { get; set; } public string Title { get; set; } public string CreatedById { get; set; } public AppUser CreatedBy { get;
public class Content
{
public int Id { get; set; }
public string Title { get; set; }
public string CreatedById { get; set; }
public AppUser CreatedBy { get; set; }
}
public class AppUser : IdentityUser
{
public ICollection<Content> Contents { get; set; }
}
然后我从我的控制器调用它,如下所示:
await UserManager.MyDeleteUserAsync(user, HttpContext.GetOwinContext());
这是因为它将内容加载到内存中,以便Entity Framework可以在保存之前将外键设置为null
使用Entity Framework的UserManager的内置功能实现这一点的正确方法是什么?可能吗?谢谢,我来看看。可能吗?谢谢,我来看看。
await UserManager.MyDeleteUserAsync(user, HttpContext.GetOwinContext());