1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
public class FilterEntityType
{
public string getEntites(
List<Type> SelectFilterType,
List<Type> ExpectFilterType,
string targetEntityCollection,
string baseFilterEntity,
string targetEntityProprtyJoinID,
string baseFilterEntityPropertyID,
string namespaceBaseFilterEntity)
{
string joinQuerys = "";
foreach (Type item in SelectFilterType)
{
joinQuerys += string.Format(
"LEFT OUTER JOIN OFTYPE({0}, {1}.{2}) AS {2}Selector ON target.{3} == {2}Selector.{4} ",
baseFilterEntity,
namespaceBaseFilterEntity,
item.Name,
targetEntityProprtyJoinID,
baseFilterEntityPropertyID);
}
string whereIns = whereIn(SelectFilterType, baseFilterEntityPropertyID);
string notIn = "";
foreach (Type item in ExpectFilterType)
{
notIn += string.Format("&& {0}Selector.{1} IS NULL ", item.Name, baseFilterEntityPropertyID);
}
string query = string.Format(
"SELECT VALUE target FROM {0} AS target {1} WHERE target.{2} IN {{{3}}} {4}",
targetEntityCollection,
joinQuerys,
targetEntityProprtyJoinID,
whereIns,
notIn
);
return query;
}
private string whereIn(List<Type> FilterType, string baseFilterEntityPropertyID)
{
string whereInQuerys = "";
foreach (Type item in FilterType)
{
whereInQuerys += string.Format(
"{0}Selector.{1},",
item.Name,
baseFilterEntityPropertyID);
}
whereInQuerys = whereInQuerys.Remove(whereInQuerys.LastIndexOf(','));
return whereInQuerys;
}
} |
Partager