protected static void RegisterQuery(string name, Func <IMatchQuery, q.SalesOrderDetailAlias, IWhereQuery> query) { q.SalesOrderDetailAlias alias; IMatchQuery matchQuery = Blueprint41.Transaction.CompiledQuery.Match(q.Node.SalesOrderDetail.Alias(out alias)); IWhereQuery partial = query.Invoke(matchQuery, alias); ICompiled compiled = partial.Return(alias).Compile(); RegisterQuery(name, compiled); }
public int Compare(object x, object y) { if (!(x is ICompiled) || !(y is ICompiled)) { return(0); } ICompiled X = x as ICompiled; ICompiled Y = y as ICompiled; return(string.Compare(X.Name, Y.Name)); }
public override List <T> LoadWhere <T>(Entity entity, ICompiled query, Parameter[] parameters, int page = 0, int pageSize = 0, bool ascending = true, params Property[] orderBy) { Transaction trans = Transaction.RunningTransaction; QueryExecutionContext context = query.GetExecutionContext(); foreach (Parameter queryParameter in parameters) { if (queryParameter.Value is null) { context.SetParameter(queryParameter.Name, null); } else { context.SetParameter(queryParameter.Name, entity.Parent.PersistenceProvider.ConvertToStoredType(queryParameter.Value.GetType(), queryParameter.Value)); } } StringBuilder sb = new StringBuilder(); sb.Append(context.CompiledQuery.QueryText); if (orderBy != null && orderBy.Length != 0) { Property odd = orderBy.FirstOrDefault(item => !entity.IsSelfOrSubclassOf(item.Parent)); if (odd != null) { throw new InvalidOperationException(string.Format("Order property '{0}' belongs to the entity '{1}' while the query only contains entities of type '{2}'.", odd.Name, odd.Parent.Name, entity.Name)); } sb.Append(" ORDER BY "); sb.Append(string.Join(", ", orderBy.Select(item => string.Concat("node.", item.Name)))); if (ascending == false) { sb.Append(" DESC "); } } if (pageSize > 0) { sb.Append(" SKIP "); sb.Append(page * pageSize); sb.Append(" LIMIT "); sb.Append(pageSize); } Dictionary <string, object?>?customState = null; var args = entity.RaiseOnNodeLoading(trans, null, sb.ToString(), context.QueryParameters, ref customState); var result = trans.Run(args.Cypher, args.Parameters); return(Load <T>(entity, args, result, trans)); }
public object ExecMethodResult(int id, string method_name) { CachedObjects.CachedEntities[id] = null; DersaSqlManager M = new DersaSqlManager(); System.Data.DataTable t = M.GetEntity(id.ToString()); if (t == null) { throw new Exception(string.Format("Table is null for entity {0}", id)); } if (t.Rows.Count < 1) { throw new Exception(string.Format("Table is empty for entity {0}", id)); } Entity ent = new Entity(t, M); CachedObjects.CachedCompiledInstances[ent.StereotypeName + id.ToString()] = null; foreach (Entity child in ent.Children) { CachedObjects.CachedCompiledInstances[child.StereotypeName + child.Id.ToString()] = null; } Logger.LogStatic("ExecMethodResult clear cache Entity" + ent.Id.ToString()); //Type nType = Type.GetType("DersaStereotypes." + ent.Stereotype.Name); ICompiled cInst = ent.GetCompiledInstance(); MethodInfo mi = cInst.GetType().GetMethod(method_name); if (mi == null) { string excMessage = "Method " + method_name + " not found "; Logger.LogStatic(excMessage); throw new Exception(excMessage); } //string userName = HttpContext.Current.User.Identity.Name; //System.Data.DataTable T = M.ExecuteSPWithParams("dbo.ENTITY$GetMethodParams", new object[] { id, method_name, userName, Util.GetPassword(userName) }); //string Params = ""; //if (T.Rows.Count > 0) // Params = T.Rows[0][0].ToString(); //object[] ParamValues = Util.GetMethodCallParameterValues(Params); //return mi.Invoke(cInst, ParamValues); return(mi.Invoke(cInst, new object[] {})); //object res = mi.Invoke(cInst, ParamValues); //string resultText = ""; //if (res != null) // resultText = res.ToString(); //return resultText; }
public static void SetImagePath(int id, string fileName) { string userName = HttpContext.Current.User.Identity.Name; string path = "/user_resources/" + userName + "/" + fileName; StereotypeBaseE target = StereotypeBaseE.GetSimpleInstance(id); CachedObjects.CachedEntities[id] = null; DersaSqlManager M = new DersaSqlManager(); System.Data.DataTable t = M.GetEntity(id.ToString()); if (t == null) { throw new Exception(string.Format("Table is null for entity {0}", id)); } if (t.Rows.Count < 1) { throw new Exception(string.Format("Table is empty for entity {0}", id)); } Entity ent = new Entity(t, M); CachedObjects.CachedCompiledInstances[ent.StereotypeName + id.ToString()] = null; foreach (Entity child in ent.Children) { CachedObjects.CachedCompiledInstances[child.StereotypeName + child.Id.ToString()] = null; } ICompiled cInst = ent.GetCompiledInstance(); MethodInfo mi = cInst.GetType().GetMethod("SetPath"); if (mi == null) { string excMessage = "Method SetPath not found "; Logger.LogStatic(excMessage); throw new Exception(excMessage); } object[] callParams = new object[2]; callParams[0] = userName; callParams[1] = path; mi.Invoke(cInst, callParams); }
public abstract List <T> LoadWhere <T>(Entity entity, ICompiled query, Parameter[] parameters, int page = 0, int pageSize = 0, bool ascending = true, params Property[] orderBy) where T : class, OGM;
public static List <TWrapper> LoadWhere(ICompiled query, Parameter[] parameters, int page, int pageSize, bool ascending = true, params Property[] orderBy) { return(Transaction.RunningTransaction.NodePersistenceProvider.LoadWhere <TWrapper>(Entity, query, parameters, page, pageSize, ascending, orderBy)); }
public static List <TWrapper> LoadWhere(ICompiled query, Parameter[] parameters, int page, int pageSize, params Property[] orderBy) { return(LoadWhere(query, parameters, page, pageSize, true, orderBy)); }
public static List <TWrapper> LoadWhere(ICompiled query, params Parameter[] parameters) { return(Transaction.RunningTransaction.NodePersistenceProvider.LoadWhere <TWrapper>(Entity, query, parameters)); }
public static List <TWrapper> LoadWhere(ICompiled query) { return(LoadWhere(query, new Parameter[0])); }
public static ICompiled CreateInstance(IStereotypedObject obj, DersaSqlManager M) { if (obj == null) { throw new Exception("obj == null"); } if (CachedObjects.CachedCompiledInstances[obj.Stereotype.Name + obj.Id.ToString()] != null) { return((ICompiled)CachedObjects.CachedCompiledInstances[obj.Stereotype.Name + obj.Id.ToString()]); } if (obj.Stereotype == null) { throw new Exception("obj.Stereotype == null, obj.name = " + obj.Name); } Type nType = GetDynamicType("DersaStereotypes." + obj.Stereotype.Name); ICompiled res = (ICompiled)Activator.CreateInstance(nType, new object[] { obj }); System.Data.DataTable t = null; if (res is ICompiledRelation) { t = M.GetAttributesForRelation(obj.Id.ToString()); } else if (res is ICompiledEntity) { t = M.GetAttributesForEntity(obj.Id.ToString()); } if (t == null) { throw new Exception("Не смогли определиться между E и R"); } foreach (System.Data.DataRow r in t.Rows) { //res[r["name"].ToString()] = r["value"].ToString(); System.Reflection.FieldInfo[] fis = nType.GetFields(); foreach (System.Reflection.FieldInfo fi in fis) { if (fi.Name == r["name"].ToString()) { object value_type = r["value_type"]; object value = null; if (value_type == null || value_type.ToString() == "1") { value = r["value"]; } else { value = r["text_value"]; } if (value == null || value is System.DBNull) { value = ""; } if (value != null) { object ConvertedValue = DIOS.Common.TypeUtil.Convert(value, fi.FieldType); fi.SetValue(res, ConvertedValue); } } } } CachedObjects.CachedCompiledInstances[obj.Stereotype.Name + obj.Id.ToString()] = res; return(res); /* * if (obj.Stereotype.Name == "Attribute") * { * Type nType = Type.GetType("DersaStereotypes." + obj.Stereotype.Name); * //Type type = typeof(DersaStereotypes.Attribute); * SqlManager M = new SqlManager(); * DersaStereotypes.Attribute res = new DersaStereotypes.Attribute((IEntity)obj); * System.Data.DataTable t = M.GetAttributesForEntity(obj.Id.ToString()); * foreach (System.Data.DataRow r in t.Rows) * { * //res[r["name"].ToString()] = r["value"].ToString(); * System.Reflection.FieldInfo[] fis = type.GetFields(); * foreach (System.Reflection.FieldInfo fi in fis) * { * if (fi.Name == r["name"].ToString()) * { * object value = r["value"]; * if (value != null) * { * object ConvertedValue = Dersa.Common.Util.Convert(value, fi.FieldType); * fi.SetValue(res, ConvertedValue); * } * } * } * } * return res; * } * if (obj.Stereotype.Name == "Entity") * { * Type type = typeof(DersaStereotypes.Entity); * SqlManager M = new SqlManager(); * DersaStereotypes.Entity res = new DersaStereotypes.Entity((IEntity)obj); * System.Data.DataTable t = M.GetAttributesForEntity(obj.Id.ToString()); * foreach (System.Data.DataRow r in t.Rows) * { * //res[r["name"].ToString()] = r["value"].ToString(); * System.Reflection.FieldInfo[] fis = type.GetFields(); * foreach (System.Reflection.FieldInfo fi in fis) * { * if (fi.Name == r["name"].ToString()) * { * object value = r["value"]; * if (value != null) * { * object ConvertedValue = Dersa.Common.Util.Convert(value, fi.FieldType); * fi.SetValue(res, ConvertedValue); * } * } * } * } * return res; * }*/ return(null); ////////////////////////////////////////////////////////////////////// //if (_stereotypesAssembly == null) // throw new NullReferenceException("Библиотека стереотипов не скомпилирована"); //Type type = _stereotypesAssembly.GetType("DersaStereotypes." + obj.Stereotype.Name); //ICompiled cs = (ICompiled)Activator.CreateInstance(type, new object[] { obj }); //System.Reflection.FieldInfo[] fis = type.GetFields(); //try //{ // foreach (System.Reflection.FieldInfo fi in fis) // { // object value = obj.GetAttribute(fi.Name).GetValue(); // if (value != null) // { // fi.SetValue(cs, value); // } // } // return cs; //} //catch (Exception ex) //{ // throw new Exception("Ошибка создания экземпляра объекта " + obj.Stereotype.Name + " : " + obj.Name + " : " + obj.Id + "\n" + ex.Message, ex); //} }
public string GetAction(string MethodName, int id, string paramString = null) {//AllowExecuteJSMethod string userName = HttpContext.Current.User.Identity.Name; StereotypeBaseE target = StereotypeBaseE.GetSimpleInstance(id); if (!target.AllowExecuteMethod(userName, MethodName)) { return(string.Format("You are not allowed to execute method {0}", MethodName)); } CachedObjects.CachedEntities[id] = null; DersaSqlManager M = new DersaSqlManager(); System.Data.DataTable t = M.GetEntity(id.ToString()); if (t == null) { throw new Exception(string.Format("Table is null for entity {0}", id)); } if (t.Rows.Count < 1) { throw new Exception(string.Format("Table is empty for entity {0}", id)); } Entity ent = new Entity(t, M); CachedObjects.CachedCompiledInstances[ent.StereotypeName + id.ToString()] = null; foreach (Entity child in ent.Children) { CachedObjects.CachedCompiledInstances[child.StereotypeName + child.Id.ToString()] = null; } ICompiled cInst = ent.GetCompiledInstance(); MethodInfo mi = cInst.GetType().GetMethod(MethodName); if (mi == null) { string excMessage = "Method " + MethodName + " not found "; Logger.LogStatic(excMessage); throw new Exception(excMessage); } object[] externalParams = new object[0]; if (paramString != null) { externalParams = JsonConvert.DeserializeObject <object[]>(paramString); } object[] callParams = new object[externalParams.Length + 1]; callParams[0] = userName; for (int i = 0; i < externalParams.Length; i++) { callParams[i + 1] = externalParams[i]; } //Logger.LogStatic(string.Format("method {0}, params count {1}", MethodName, callParams.Length)); object result = mi.Invoke(cInst, new object[] { callParams }); if (result == null) { return(null); } if (result is string) { return(result.ToString()); } return(JsonConvert.SerializeObject(result)); }
public void OGMImplPlannerHitsUsing() { using (ConsoleOutput output = new ConsoleOutput()) { using (Transaction.Begin(true)) { Person p1 = new Person { Name = "Martin Sheen", }; Person p2 = new Person { Name = "Michael Douglas", }; Person p3 = new Person { Name = "Oliver Stone", }; Person p4 = new Person { Name = "Rob Reiner", }; Movie wallstreet = new Movie { Title = "Wall Street" }; Movie tap = new Movie { Title = "The American President" }; p1.ActedInMovies.Add(tap); p1.ActedInMovies.Add(wallstreet); p2.ActedInMovies.Add(tap); p2.ActedInMovies.Add(wallstreet); p3.DirectedMovies.Add(wallstreet); p4.DirectedMovies.Add(tap); Transaction.Commit(); } } using (ConsoleOutput output = new ConsoleOutput()) { string consoleOutput; using (Transaction.Begin()) { // Force to use index ICompiled compiled = Transaction.CompiledQuery .Match(node.Movie.Alias(out MovieAlias m)) .UsingIndex(m.Title) .Where(m.Title == "Wall Street") .Return(m.Title) .Compile(); var result = compiled.GetExecutionContext().Execute(); var a = result[0] as IDictionary <string, object>; Assert.AreEqual(a["Column1"], "Wall Street"); consoleOutput = output.GetOuput(); Assert.IsTrue(Regex.IsMatch(consoleOutput, @"(MATCH \(n0:Movie\))[^a-zA-Z,0-9]*(USING INDEX n0:Movie\(Title\))[^a-zA-Z,0-9]*(WHERE \(n0.Title = ""Wall Street""\))[^a-zA-Z,0-9]*(RETURN DISTINCT n0.Title AS Column1)")); // With relationship compiled = Transaction.CompiledQuery .Match(node.Movie.Alias(out MovieAlias ma).Out.PERSON_DIRECTED.In.Person.Alias(out PersonAlias p)) .UsingIndex(ma.Title) .Where(ma.Title == "Wall Street") .Return(ma.Title, p.Name) .Compile(); result = compiled.GetExecutionContext().Execute(); a = result[0] as IDictionary <string, object>; Assert.AreEqual(a["Column1"], "Wall Street"); Assert.AreEqual(a["Column2"], "Oliver Stone"); consoleOutput = output.GetOuput(); Assert.IsTrue(Regex.IsMatch(consoleOutput, @"(MATCH \(n0:Movie\)<-\[:DIRECTED_BY\]-\(n1:Person\))[^a-zA-Z,0-9]*(USING INDEX n0:Movie\(Title\))[^a-zA-Z,0-9]*(WHERE \(n0.Title = ""Wall Street""\))[^a-zA-Z,0-9]*(RETURN DISTINCT n0.Title AS Column1, n1.Name AS Column2)")); // Use label scan compiled = Transaction.CompiledQuery .Match(node.Movie.Alias(out MovieAlias mas)) .UsingScan(mas) .Where(mas.Title == "Wall Street") .Return(mas.Title) .Compile(); result = compiled.GetExecutionContext().Execute(); a = result[0] as IDictionary <string, object>; Assert.AreEqual(a["Column1"], "Wall Street"); consoleOutput = output.GetOuput(); Assert.IsTrue(Regex.IsMatch(consoleOutput, @"(MATCH \(n0:Movie\))[^a-zA-Z,0-9]*(USING SCAN n0:Movie)[^a-zA-Z,0-9]*(WHERE \(n0.Title = ""Wall Street""\))[^a-zA-Z,0-9]*(RETURN DISTINCT n0.Title AS Column1)")); // use label scan with relationship compiled = Transaction.CompiledQuery .Match(node.Movie.Alias(out MovieAlias mar).Out.PERSON_DIRECTED.In.Person.Alias(out PersonAlias par)) .UsingScan(mar) .UsingScan(par) .Where(mar.Title == "Wall Street") .Return(mar.Title, par.Name) .Compile(); result = compiled.GetExecutionContext().Execute(); a = result[0] as IDictionary <string, object>; Assert.AreEqual(a["Column1"], "Wall Street"); Assert.AreEqual(a["Column2"], "Oliver Stone"); consoleOutput = output.GetOuput(); Assert.IsTrue(Regex.IsMatch(consoleOutput, @"(MATCH \(n0:Movie\)<-\[:DIRECTED_BY\]-\(n1:Person\))[^a-zA-Z,0-9]*(USING SCAN n0:Movie)[^a-zA-Z,0-9]*(USING SCAN n1:Person)[^a-zA-Z,0-9]*(WHERE \(n0.Title = ""Wall Street""\))[^a-zA-Z,0-9]*(RETURN DISTINCT n0.Title AS Column1, n1.Name AS Column2)")); // use label scan and index compiled = Transaction.CompiledQuery .Match(node.Movie.Alias(out MovieAlias msi).Out.PERSON_DIRECTED.In.Person.Alias(out PersonAlias psi)) .UsingIndex(msi.Title) .UsingScan(psi) .Where(msi.Title == "Wall Street") .Return(msi.Title, psi.Name) .Compile(); result = compiled.GetExecutionContext().Execute(); a = result[0] as IDictionary <string, object>; Assert.AreEqual(a["Column1"], "Wall Street"); Assert.AreEqual(a["Column2"], "Oliver Stone"); consoleOutput = output.GetOuput(); Assert.IsTrue(Regex.IsMatch(consoleOutput, @"(MATCH \(n0:Movie\)<-\[:DIRECTED_BY\]-\(n1:Person\))[^a-zA-Z,0-9]*(USING INDEX n0:Movie\(Title\))[^a-zA-Z,0-9]*(USING SCAN n1:Person)[^a-zA-Z,0-9]*(WHERE \(n0.Title = ""Wall Street""\))[^a-zA-Z,0-9]*(RETURN DISTINCT n0.Title AS Column1, n1.Name AS Column2)")); } } }
public void OGMImplQueryOptionalMatch() { using (ConsoleOutput output = new ConsoleOutput()) { using (Transaction.Begin(true)) { Person p1 = new Person { Name = "Martin Sheen", }; Person p2 = new Person { Name = "Michael Douglas", }; Person p3 = new Person { Name = "Oliver Stone", }; Person p4 = new Person { Name = "Rob Reiner", }; Movie wallstreet = new Movie { Title = "Wall Street" }; Movie tap = new Movie { Title = "The American President" }; p1.ActedInMovies.Add(tap); p1.ActedInMovies.Add(wallstreet); p2.ActedInMovies.Add(tap); p2.ActedInMovies.Add(wallstreet); p3.DirectedMovies.Add(wallstreet); p4.DirectedMovies.Add(tap); Transaction.Commit(); } } using (ConsoleOutput output = new ConsoleOutput()) { string outputConsole; using (Transaction.Begin()) { ICompiled compiled = Transaction.CompiledQuery .Match(node.Person.Alias(out PersonAlias p)) .Where(p.Name.Contains("Martin Sheen")) .OptionalMatch(node.Movie.Alias(out MovieAlias m)) .Return(m.Title) .OrderBy(m.Title) .Compile(); var result = compiled.GetExecutionContext().Execute(); var a = result[0] as IDictionary <string, object>; var b = result[1] as IDictionary <string, object>; Assert.AreEqual(a["Column1"], "The American President"); Assert.AreEqual(b["Column1"], "Wall Street"); outputConsole = output.GetOuput(); Assert.IsTrue(Regex.IsMatch(outputConsole, @"(MATCH \(n0:Person\))[^a-zA-Z,0-9]*(WHERE \(n0\.Name CONTAINS ""Martin Sheen""\))[^a-zA-Z,0-9]*(OPTIONAL MATCH \(n1:Movie\))[^a-zA-Z,0-9]*(RETURN DISTINCT n1\.Title AS Column1)[^a-zA-Z,0-9]*(ORDER BY n1\.Title)")); compiled = Transaction.CompiledQuery .Match(node.Person.Alias(out PersonAlias pa)) .Where(pa.Name.Contains("Martin Sheen")) .OptionalMatch(pa.In.PERSON_DIRECTED.Out.Movie.Alias(out MovieAlias ma)) .Return(pa.Name, ma.Title) .OrderBy(ma.Title) .Compile(); result = compiled.GetExecutionContext().Execute(); a = result[0] as IDictionary <string, object>; Assert.AreEqual(a["Column1"], "Martin Sheen"); Assert.IsNull(a["Column2"]); outputConsole = output.GetOuput(); Assert.IsTrue(Regex.IsMatch(outputConsole, @"(MATCH \(n0:Person\))[^a-zA-Z,0-9]*(WHERE \(n0\.Name CONTAINS ""Martin Sheen""\))[^a-zA-Z,0-9]*(OPTIONAL MATCH \(n0\)-\[\:DIRECTED_BY\]\-\>\(n1:Movie\))[^a-zA-Z,0-9]*(RETURN DISTINCT n0\.Name AS Column1, n1\.Title AS Column2)[^a-zA-Z,0-9]*(ORDER BY n1\.Title)")); compiled = Transaction.CompiledQuery .Match(node.Person.Alias(out PersonAlias pap).In.PERSON_DIRECTED.Out.Movie.Alias(out MovieAlias mam)) .Where(pap.Name.Contains("Martin Sheen")) .Return(mam.Title) .OrderBy(mam.Title) .Compile(); result = compiled.GetExecutionContext().Execute(); Assert.Zero(result.Count); outputConsole = output.GetOuput(); Assert.IsTrue(Regex.IsMatch(outputConsole, @"(MATCH \(n0:Person\)-\[\:DIRECTED_BY\]\-\>\(n1:Movie\))[^a-zA-Z,0-9]*(WHERE \(n0\.Name CONTAINS ""Martin Sheen""\))[^a-zA-Z,0-9]*(RETURN DISTINCT n1\.Title AS Column1)[^a-zA-Z,0-9]*(ORDER BY n1\.Title)")); } } }
public void OGMImplQuery() { using (ConsoleOutput output = new ConsoleOutput()) { using (Transaction.Begin(true)) { Person p1 = new Person { Name = "Joe Smith", City = new City() { Name = "New York" } }; p1.City.Restraurants.Add(new Restaurant { Name = "Mcdonalds" }); p1.City.Restraurants.Add(new Restaurant { Name = "Shakeys" }); p1.City.Restraurants.Add(new Restaurant { Name = "Starbucks" }); p1.City.Restraurants.Add(new Restaurant { Name = "Bo's Coffee" }); p1.City.Restraurants.Add(new Restaurant { Name = "Chattime" }); Person p2 = new Person { Name = "Jane Smith", City = new City() { Name = "California" } }; Person p3 = new Person { Name = "Bob Smith", City = p1.City }; p2.City.Restraurants.Add(new Restaurant { Name = "Pink's Hot Dogs" }); p2.City.Restraurants.Add(new Restaurant { Name = "World Famous" }); p2.City.Restraurants.Add(new Restaurant { Name = "Barone's" }); p2.City.Restraurants.Add(new Restaurant { Name = "Providence" }); p2.City.Restraurants.Add(new Restaurant { Name = "La Taqueria" }); p1.Restaurants.Add(p1.City.Restraurants[0]); p1.Restaurants.Add(p1.City.Restraurants[1]); p1.Restaurants.Add(p1.City.Restraurants[2]); p1.Restaurants.Add(p1.City.Restraurants[3]); p1.Restaurants.Add(p1.City.Restraurants[4]); p1.Restaurants.Add(p2.City.Restraurants[0]); p1.Restaurants.Add(p2.City.Restraurants[1]); p1.Restaurants.Add(p2.City.Restraurants[2]); p1.Restaurants.Add(p2.City.Restraurants[3]); p1.Restaurants.Add(p2.City.Restraurants[4]); p2.Restaurants.Add(p1.City.Restraurants[0]); p2.Restaurants.Add(p1.City.Restraurants[1]); p2.Restaurants.Add(p1.City.Restraurants[2]); p2.Restaurants.Add(p1.City.Restraurants[3]); p2.Restaurants.Add(p1.City.Restraurants[4]); p2.Restaurants.Add(p2.City.Restraurants[0]); p2.Restaurants.Add(p2.City.Restraurants[1]); p2.Restaurants.Add(p2.City.Restraurants[2]); p2.Restaurants.Add(p2.City.Restraurants[2]); p2.Restaurants.Add(p2.City.Restraurants[3]); p2.Restaurants.Add(p2.City.Restraurants[4]); Transaction.Commit(); } } string outputConsole; using (ConsoleOutput output = new ConsoleOutput()) { using (Transaction.Begin()) { ICompiled compiled = Transaction.CompiledQuery .Match(node.Person.Alias(out PersonAlias p)) .Where(p.Name.Contains("Smith")) .Return(p) .Compile(); List <Person> searchResult = Person.LoadWhere(compiled); Assert.Greater(searchResult.Count, 0); outputConsole = output.GetOuput(); Assert.IsTrue(Regex.IsMatch(outputConsole, @"(MATCH \(n0:Person\))[^a-zA-Z,0-9]*(WHERE \(n0\.Name CONTAINS ""Smith""\)[^a-zA-Z,0-9]*RETURN DISTINCT n0 AS Column1)")); compiled = Transaction.CompiledQuery .Match(node.Person.Alias(out PersonAlias pWithLimit)) .Where(pWithLimit.Name.Contains("Smith")) .Return(pWithLimit) .Limit(1) .Compile(); searchResult = Person.LoadWhere(compiled); Assert.AreEqual(searchResult.Count, 1); outputConsole = output.GetOuput(); Assert.IsTrue(Regex.IsMatch(outputConsole, @"(MATCH \(n0:Person\))[^a-zA-Z,0-9]*(WHERE \(n0.Name CONTAINS ""Smith""\)[^a-zA-Z,0-9]*RETURN DISTINCT n0 AS Column1)[^a-zA-Z,0-9]*(LIMIT 1)")); compiled = Transaction.CompiledQuery .Match(node.Person.Alias(out var pR).In.PERSON_EATS_AT.Out.Restaurant.Alias(out var rP)) .Where(rP.Name == "Shakeys") .Return(pR) .OrderBy(pR.Name) .Compile(); searchResult = Person.LoadWhere(compiled); Assert.AreEqual(searchResult.Count, 2); Assert.AreEqual(searchResult[0].Name, "Jane Smith"); Assert.AreEqual(searchResult[1].Name, "Joe Smith"); outputConsole = output.GetOuput(); Assert.IsTrue(Regex.IsMatch(outputConsole, @"(MATCH \(n0:Person\)-\[:EATS_AT\]->\(n1:Restaurant\))[^a-zA-Z,0-9]*(WHERE \(n1\.Name = ""Shakeys""\))[^a-zA-Z,0-9]*(RETURN DISTINCT n0 AS Column1)[^a-zA-Z,0-9]*(ORDER BY n0.Name)")); } } }