| | 1 | | using Microsoft.Xrm.Sdk.Query; |
| | 2 | | using System.Linq; |
| | 3 | |
|
| | 4 | | namespace FakeXrmEasy.Extensions |
| | 5 | | { |
| | 6 | | public static class QueryExpressionExtensions |
| | 7 | | { |
| | 8 | | public static string GetEntityNameFromAlias(this QueryExpression qe, string sAlias) |
| 452 | 9 | | { |
| 452 | 10 | | if (sAlias == null) |
| 0 | 11 | | return qe.EntityName; |
| | 12 | |
|
| 452 | 13 | | var linkedEntity = qe.LinkEntities |
| 1145 | 14 | | .Where(le => le.EntityAlias != null && le.EntityAlias.Equals(sAlias)) |
| 452 | 15 | | .FirstOrDefault(); |
| | 16 | |
|
| 452 | 17 | | if (linkedEntity != null) |
| 435 | 18 | | { |
| 435 | 19 | | return linkedEntity.LinkToEntityName; |
| | 20 | | } |
| | 21 | |
|
| | 22 | | //If the alias wasn't found, it means it could be any of the EntityNames |
| 17 | 23 | | return sAlias; |
| 452 | 24 | | } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Makes a deep clone of the Query Expression |
| | 28 | | /// </summary> |
| | 29 | | /// <param name="qe">Query Expression</param> |
| | 30 | | /// <returns></returns> |
| | 31 | | public static QueryExpression Clone(this QueryExpression qe) |
| 1665 | 32 | | { |
| 1665 | 33 | | return qe.Copy(); |
| 1665 | 34 | | } |
| | 35 | | } |
| | 36 | | } |