Saturday, May 12, 2018

NHibernate 5 IQueryable's DML use with caution

public class User
{
    // ...properties here

    public IEnumerable<ExternalLogin> ExternalLogins { get; protected set; } = new List<ExternalLogin>();

    public void DeleteAllExternalLogins()
    {
        await this.ExternalLogins.AsQueryable()
        .DeleteAsync(new System.Threading.CancellationToken());
    }
}    

public class ExternalLogin
{
    protected User User { get; }

    internal ExternalLogin(User applicationUser) => this.User = applicationUser;
    
    public int Id { get; protected set; }

    public string LoginProvider { get; internal protected set; } // provider: facebook, google, etc

    public string ProviderKey { get; internal protected set; } // user's id from facebook, google, etc

    public string DisplayName { get; internal protected set; } // seems same as provider   
}        



The above DML will not put a user id filter, instead it will just issue this:

delete from external_login;


Happy Coding!

No comments:

Post a Comment