predicate - With Dapper Extensions, how do I sort by random? -
This duplicate extension can be obtained with a predicate sorting: My question is, how do I apply random sorting (i.e. RAND) in SQL for predicates
.Sort & LT; Person & gt; (P = & gt; p.LastName)
After the
Thus Predicates.Sort actually produces an ISort compatible interface that is defined:
< Code> public interface ISort {string property name {get; Set; } Moving the Bowl {Get; Set; }}
It seems that we have a chance to set the property name for "RAND ()" or some things, right? ... but unfortunately, this interface is used in this way:
if (sort = null & amp;! & Sort.Any ()) {sql.Append ("By order") .Append (sort = Selection = GetColumnName (classMap, S.PropertyName, False) + (S. Esconding? "ASC": "DESC")) .andendings ()); }
Therefore Dapper Extensions actually check that the name of the passphrase is a column name. And GetColumnName is defined as:
public virtual string GetColumnName (IClassMapper map, string property, bool includeAlias) {IPropertyMap propertyMap = map.Properties.SingleOrDefault (p = & gt; p. Name equal (Property Name, String Communications, Inventory Culture Ignore Case)); If (propertyMap == faucet) {new argument expression (string.Format ("could not find '{0}' in mapping.", PropertyName)); } GetColumnName (map, property map, included alias); }
Therefore, the string should not actually be the name of a column, but a property name (they named the field for an objective in the ISort interface, right?).
So, to implement something you need, you need to customize your SQL generator.
For more information, reference to sources is the best way:
predicate:
SqlGenerator:
PS: I can not post a link to the repo root due to the representative of the beginning, hope you can guess it;)
PPS: This is true for the entire forecast system in Dopper Extensions. I believe it should be much more restructured to allow more than plain-front column-based restrictions.
Comments
Post a Comment