You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 24, 2026. It is now read-only.
StrutTower edited this page Jul 4, 2024
·
1 revision
If your query requires JOINs or OR statements, you'll have to manually write the SQL statement. The syntax of your SQL query will need to value valid for your current database.
Caution
ALWAYS use parameters for any variables that are coming from outside the current function. Concatenating the variables directly into the query leaves your code open to SQL Injection
publicclassPersonRepository:DbRepository<Person>{publicPersonRepository(UnitOfWorkuow):base(uow.DbAdapter){}// Get all entities that are inactive or the display name is NULLpublicList<Person>GetInactiveOrWithoutDisplayName(){QueryBuilderquery=GetQueryBuilder();query.SqlQuery+=$"WHERE t.IsActive = 0 "+// Hard-coding the value 0 is safe here$"OR DisplayName IS NULL ";returnGetEntities(query);}// Get all entities based on a join to another table. This does not SELECT any data from the joined table.publicList<Person>GetWithTransactionsAfterDate(DateTimedatetime){QueryBuilderquery=GetQueryBuilder();query.SqlQuery+=$"INNER JOIN transaction t ON {TableName}.ID = t.PersonID "+$"WHERE t.DateTime > @DateTime ";query.AddParameter("@DateTime",datetime);// Add the datetime value as an parameterreturnGetEntities(query);}}