Last active
August 29, 2015 14:17
-
-
Save pofider/3cae0c423eb084e4bf79 to your computer and use it in GitHub Desktop.
Adding where condition into NHibernate update statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MultitenantEntityPersister : SingleTableEntityPersister | |
{ | |
public MultitenantEntityPersister(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping) | |
: base(persistentClass, cache, factory, mapping) | |
{ | |
} | |
protected override NHibernate.SqlCommand.SqlCommandInfo GenerateUpdateString(bool[] includeProperty, int j, bool useRowId) | |
{ | |
var index = base.GetPropertyIndex("TenantId"); | |
foreach (bool p in includeProperty) | |
{ | |
if (!p) | |
index--; | |
} | |
var result = base.GenerateUpdateString(includeProperty, j, useRowId); | |
var tenantWhereBuilder = new SqlStringBuilder(); | |
tenantWhereBuilder | |
.Add(" AND ") | |
.Add("TenantId") | |
.Add(" = ") | |
.Add(Parameter.WithIndex(index)); | |
result = new SqlCommandInfo(result.Text.Append(tenantWhereBuilder.ToSqlString()), result.ParameterTypes); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment