public void CartesianProduct() { RequiredDataContainer ModelData = VirtualMapDataProvider.VirtualMapModel(); QueryableEntity Person = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")); QueryableEntity Pet = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Pet")); CartesianProductOperator Op = new CartesianProductOperator(Person, Pet, ModelData.ERMongoMapping); VirtualMap CartersianVMap = Op.ComputeVirtualMap(); Assert.IsNotNull(CartersianVMap, "Cartesian Product virtual map cannot be null"); List <string> VirtualMapRules = CartersianVMap.GetRulesAsStringList(); List <string> RulesToMatch = new List <string>() { "_id", "name", "age", "data_Pet._id", "data_Pet.name", "data_Pet.type", "data_Pet.ownerId", }; Assert.IsTrue(!VirtualMapRules.Except(RulesToMatch).Any() && !RulesToMatch.Except(VirtualMapRules).Any(), "Virtual maps do not match"); }
public void RelationshipJoin() { RequiredDataContainer ModelData = VirtualMapDataProvider.VirtualMapModel(); QueryableEntity Person = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")); QueryableEntity Pet = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Pet")); RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator(Person, (Relationship)ModelData.EntityRelationshipModel.FindByName("HasPet"), new List <QueryableEntity>() { Pet }, ModelData.ERMongoMapping); VirtualMap RJoinVMap = RJoinOp.ComputeVirtualMap(); List <string> VirtualMapRules = RJoinVMap.GetRulesAsStringList(); Assert.IsNotNull(RJoinVMap, "Virtual map cannot be null"); List <string> RulesToMatch = new List <string>() { "_id", "name", "age", "data_HasPet.Pet_petId", "data_HasPet.Pet_name", "data_HasPet.Pet_type", "data_HasPet.Pet_ownerId" }; Assert.IsTrue(!VirtualMapRules.Except(RulesToMatch).Any() && !RulesToMatch.Except(VirtualMapRules).Any()); }
public async Task DeleteAsync(TKey entityId) { TEntity entity = QueryableEntity.FirstOrDefault(p => p.Id.ToString().Equals(entityId.ToString())); await DeleteAsync(entity); await SaveChangesAsync(); }
public static void Main() { Console.WriteLine("Running..."); DataContainer data = MarketingCMSDataProvider.MapEntitiesToCollections(); QueryableEntity User = new QueryableEntity(data.EntityRelationshipModel.FindByName("User")); QueryableEntity Product = new QueryableEntity(data.EntityRelationshipModel.FindByName("Product")); QueryableEntity Store = new QueryableEntity(data.EntityRelationshipModel.FindByName("Store")); QueryableEntity Category = new QueryableEntity(data.EntityRelationshipModel.FindByName("Category")); string Query = MarketingCMS._getQueryForTestAllProducts(data, Product, Store, Category, User); QueryRunner Runner = new QueryRunner("mongodb://127.0.0.1:27017", "pesquisa_cms"); string result = Runner.GetJSON(Query); JToken JSONResult = JToken.Parse(result); if (JSONResult.Type == JTokenType.Array) { Console.WriteLine("This is an array"); JContainer ResultArray = (JContainer)JSONResult; Console.WriteLine("Count: {0}", ResultArray.Count); } using (StreamWriter sw = new StreamWriter(@"result.json", false)) { sw.Write(result); sw.Close(); } }
public static void Main() { DataContainer data = CreateDataContainer(); QueryableEntity Person = new QueryableEntity(data.EntityRelationshipModel.FindByName("Person")); QueryableEntity Car = new QueryableEntity(data.EntityRelationshipModel.FindByName("Car")); Relationship Drives = (Relationship)data.EntityRelationshipModel.FindByName("Drives"); ModelMapping Map = data.ERMongoMapping; RelationshipJoinOperator RJoinDrives = new RelationshipJoinOperator( Person, Drives, new List <QueryableEntity>() { Car }, Map); FromArgument From = new FromArgument(Person, Map); QueryGenerator QueryGen = new QueryGenerator(From, new List <AlgebraOperator>() { RJoinDrives }); string query = QueryGen.Run(); Console.WriteLine(query); }
internal static Students studentLogin(String matricno, String password, bool withoutpassword = false) { var studente = (from s in new QueryableEntity <Students>() where s.MatricNo == matricno select s).First(); var studentexists = new QueryableEntity <Students>().Any(x => x.MatricNo == matricno); if (!studentexists) { return(null); } var latestcompany = (from sp in new QueryableEntity <StudentProgrammes>() where sp.MatricNo == matricno orderby sp.Session descending select sp.Company).ToList().AppFirst(); if (latestcompany == null) { throw new Exception("StudentProgramme Not Found for " + matricno); } String passwordString = DatabaseHandler.DefaultDatabaseHandlerObject.getPasswordString(password); //String passwordString2 = AppFramework.AppClasses.Util.md5(password); var students = (from student in new QueryableEntity <Students>() join stdprog in new QueryableEntity <StudentProgrammes>() on student.MatricNo equals stdprog.MatricNo where student.MatricNo == matricno && (student.Password == passwordString || withoutpassword) && student.Company == latestcompany && stdprog.Company == latestcompany select student).ToList().AppFirst(); return(students); }
/// <summary> /// Initialize a new ComputedEntity instance /// </summary> /// <param name="Name">Computed Entity name</param> /// <param name="Attributes">Attributes</param> public ComputedEntity(string Name, QueryableEntity SourceEntity, Relationship Relationship, List <QueryableEntity> TargetEntities) { this.Name = Name; this.SourceEntity = SourceEntity; this.Relationship = Relationship; this.TargetEntities = TargetEntities; }
public override void ExitSelectAttributeOrFunction([NotNull] QueryBuilderQueriesParser.SelectAttributeOrFunctionContext context) { List <ProjectArgument> Arguments = new List <ProjectArgument>(); foreach (var selectAttribute in context.attributeOrFunction().Where(af => af.simpleAttribute() != null)) { var sa = selectAttribute.simpleAttribute(); QueryableEntity qElement = new QueryableEntity(metadata.EntityRelationshipModel.FindByName(sa.elementName.Text)); Arguments.Add(new ProjectArgument(qElement.GetAttribute(sa.attribute.Text), qElement, new QueryBuilder.Mongo.Expressions.BooleanExpr(true))); } ProjectOp = new ProjectStage(Arguments, metadata.ERMongoMapping); }
public void ProjectSimpleAttributes() { // Asserts if the query result for a relationship join operation is equal // to a handcrafted query RequiredDataContainer ModelData = ProjectDataProvider.SimpleModel(); // Load handcrafted query string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/projectQuerySimple.js"); // Assert if the handcrafted query is not null Assert.IsNotNull(HandcraftedQuery); // Prepare query generator QueryableEntity Person = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")); List <ProjectArgument> Arguments = new List <ProjectArgument>(); Arguments.Add(new ProjectArgument(Person.GetAttribute("personId"), Person, new BooleanExpr(false))); Arguments.Add(new ProjectArgument(Person.GetAttribute("name"), Person, new BooleanExpr(true))); Arguments.Add(new ProjectArgument(Person.GetAttribute("age"), Person, new BooleanExpr(true))); ProjectStage ProjectOp = new ProjectStage(Arguments, ModelData.ERMongoMapping); List <AlgebraOperator> OpList = new List <AlgebraOperator> { ProjectOp }; FromArgument StartArg = new FromArgument(new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")), ModelData.ERMongoMapping); QueryGenerator QueryGen = new QueryGenerator(StartArg, OpList); string GeneratedQuery = QueryGen.Run(); // Assert if generated query is not null Assert.IsNotNull(GeneratedQuery); // Run Queries QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "ceManyToMany2"); string HandcraftedResult = Runner.GetJSON(HandcraftedQuery); string GeneratedResult = Runner.GetJSON(GeneratedQuery); // Check if either result is null Assert.IsNotNull(HandcraftedResult); Assert.IsNotNull(GeneratedResult); // Check if both results are equal Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult))); }
private QueryableEntity getFirstEntityOnly(QueryableEntity qEntity) { if (qEntity.Element.GetType() == typeof(Entity)) { return(qEntity); } else if (qEntity.Element.GetType() == typeof(ComputedEntity)) { ComputedEntity ce = qEntity.Element as ComputedEntity; return(getFirstEntityOnly(ce.SourceEntity)); } else { throw new InvalidOperationException("There should not be another element type here!"); } }
private FromArgument getStartArg(QueryableEntity qEntity) { if (qEntity.Element.GetType() == typeof(Entity)) { return(new FromArgument(qEntity, metadata.ERMongoMapping)); } else if (qEntity.Element.GetType() == typeof(ComputedEntity)) { ComputedEntity ce = qEntity.Element as ComputedEntity; return(getStartArg(ce.SourceEntity)); } else { throw new InvalidOperationException("There should not be another element type here!"); } }
override public void ExitSimpleEntity(QueryBuilderQueriesParser.SimpleEntityContext context) { string simpleEntityAlias = null; if (context.simpleEntityAlias != null) { simpleEntityAlias = context.simpleEntityAlias.Text; } var qEntity = new QueryableEntity(metadata.EntityRelationshipModel.FindByName(context.simpleEntityName.Text), simpleEntityAlias); if (qEntity.Element.GetType() != typeof(Entity)) { throw new Exception($"Element {qEntity.Element.Name} is not an Entity!"); } context.qEntity = qEntity; }
public static string _getQueryForTestAllProducts(DataContainer DataMap, QueryableEntity Product, QueryableEntity Store, QueryableEntity Category, QueryableEntity User) { RelationshipJoinOperator RJoinProductUser = new RelationshipJoinOperator( Product, (Relationship)DataMap.EntityRelationshipModel.FindByName("UserProducts"), new List <QueryableEntity>() { User }, DataMap.ERMongoMapping); RelationshipJoinOperator RJoinProductStore = new RelationshipJoinOperator( Product, (Relationship)DataMap.EntityRelationshipModel.FindByName("StoreProducts"), new List <QueryableEntity>() { Store }, DataMap.ERMongoMapping); RelationshipJoinOperator RJoinProductCategory = new RelationshipJoinOperator( Product, (Relationship)DataMap.EntityRelationshipModel.FindByName("CategoryProducts"), new List <QueryableEntity>() { Category }, DataMap.ERMongoMapping); SortArgument SortArg = new SortArgument(Product, Product.GetAttribute("product_id"), MongoDBSort.Ascending); SortStage SortOp = new SortStage(new List <SortArgument>() { SortArg }, DataMap.ERMongoMapping); List <AlgebraOperator> Operators = new List <AlgebraOperator>() { RJoinProductUser, RJoinProductStore, RJoinProductCategory, SortOp }; FromArgument FromArg = new FromArgument(Product, DataMap.ERMongoMapping); QueryGenerator QueryGen = new QueryGenerator(FromArg, Operators); string Query = QueryGen.Run(); return(Query); }
private List <RelationshipJoinOperator> getRelationshipJoinOperators(QueryableEntity qEntity) { var ret = new List <RelationshipJoinOperator>(); if (qEntity.Element.GetType() == typeof(ComputedEntity)) { ComputedEntity ce = qEntity.Element as ComputedEntity; ret.AddRange(getRelationshipJoinOperators(ce.SourceEntity)); ret.Add(new RelationshipJoinOperator(getFirstEntityOnly(ce.SourceEntity), ce.Relationship, ce.RelationshipAlias, ce.TargetEntities, metadata.ERMongoMapping)); } return(ret); }
public void ProjectStageShowFields() { //RequiredDataContainer ModelData = VirtualMapDataProvider.VirtualMapModel(); var ModelData = QueryBuilderParser.ParseMapping(Utils.ReadMappingFile("Mappings/virtual-map.mapping")); QueryableEntity Person = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")); QueryableEntity Pet = new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Pet")); RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator( Person, (Relationship)ModelData.EntityRelationshipModel.FindByName("HasPet"), new List <QueryableEntity>() { Pet }, ModelData.ERMongoMapping); VirtualMap RJoinVMap = RJoinOp.ComputeVirtualMap(); Assert.IsNotNull(RJoinVMap, "RJOIN Virtual map cannot be null"); List <ProjectArgument> ProjectArguments = new List <ProjectArgument>(); ProjectArguments.Add(new ProjectArgument(Person.GetAttribute("name"), Person, new BooleanExpr(true))); ProjectArguments.Add(new ProjectArgument(Person.GetAttribute("age"), Person, new BooleanExpr(true))); ProjectArguments.Add(new ProjectArgument(Pet.GetAttribute("name"), Pet, new BooleanExpr(true))); ProjectStage ProjectOp = new ProjectStage(ProjectArguments, RJoinVMap); VirtualMap ProjectVirtualMap = ProjectOp.ComputeVirtualMap(RJoinVMap); Assert.IsNotNull(ProjectVirtualMap, "Project virtual map cannot be null"); List <string> VirtualMapRules = ProjectVirtualMap.GetRulesAsStringList(); List <string> RulesToMatch = new List <string>() { "name", "age", "data_HasPet.Pet_name", }; Assert.IsTrue(!VirtualMapRules.Except(RulesToMatch).Any() && !RulesToMatch.Except(VirtualMapRules).Any(), "Virtual maps do not match"); }
private void GenerateQuery(RequiredDataContainer Container, string Database) { QueryableEntity Aluno = new QueryableEntity(Container.EntityRelationshipModel.FindByName("Aluno")); QueryableEntity Endereco = new QueryableEntity(Container.EntityRelationshipModel.FindByName("Endereco")); RelationshipJoinOperator RJoinOp = new RelationshipJoinOperator( Aluno, (Relationship)Container.EntityRelationshipModel.FindByName("AlunoMora"), new List <QueryableEntity>() { Endereco }, Container.ERMongoMapping); SortArgument SortArg = new SortArgument(Aluno, Aluno.Element.GetIdentifierAttribute(), MongoDBSort.Ascending); SortStage SortOp = new SortStage(new List <SortArgument>() { SortArg }, Container.ERMongoMapping); List <AlgebraOperator> OperatorList = new List <AlgebraOperator>() { RJoinOp, SortOp }; FromArgument FromArg = new FromArgument(Aluno, Container.ERMongoMapping); QueryGenerator QueryGen = new QueryGenerator(FromArg, OperatorList); string Query = QueryGen.Run(); Beautifier jsB = new Beautifier(); queryBox.Text = jsB.Beautify(Query); QueryRunner QueryRunner = new QueryRunner("mongodb://localhost:27017", Database); string Result = QueryRunner.GetJSON(Query); resultBox.Text = Result.PrettyPrintJson(); }
public void GetAllProductsTest() { DataContainer DataMap = MarketingCMSDataProvider.MapEntitiesToCollections(); DataContainer DataMap2 = MarketingCMSDataProvider.MapEntitiesToCollectionDuplicates(); DataContainer DataMap3 = MarketingCMSDataProvider.MapEntitiesToCollectionCategoryDuplicated(); DataContainer DataMap4 = MarketingCMSDataProvider.MapEntitiesToCollectionsStoreDuplicated(); DataContainer DataMap5 = MarketingCMSDataProvider.MapEntitiesToCollectionsUserDuplicated(); QueryableEntity Product = new QueryableEntity(DataMap.EntityRelationshipModel.FindByName("Product")); QueryableEntity Store = new QueryableEntity(DataMap.EntityRelationshipModel.FindByName("Store")); QueryableEntity Category = new QueryableEntity(DataMap.EntityRelationshipModel.FindByName("Category")); QueryableEntity User = new QueryableEntity(DataMap.EntityRelationshipModel.FindByName("User")); string Query = _getQueryForTestAllProducts(DataMap, Product, Store, Category, User); string Query2 = _getQueryForTestAllProducts(DataMap2, Product, Store, Category, User); string Query3 = _getQueryForTestAllProducts(DataMap3, Product, Store, Category, User); string Query4 = _getQueryForTestAllProducts(DataMap4, Product, Store, Category, User); string Query5 = _getQueryForTestAllProducts(DataMap5, Product, Store, Category, User); QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms"); string Result = Runner.GetJSON(Query); QueryRunner Runner2 = new QueryRunner("mongodb://localhost:27017", "pesquisa_cms_duplicados"); string Result2 = Runner2.GetJSON(Query2); //QueryRunner Runner3 = new QueryRunner( "mongodb://localhost:27017", "pesquisa_cms_category_duplicado" ); //string Result3 = Runner3.GetJSON( Query3 ); //QueryRunner Runner4 = new QueryRunner( "mongodb://localhost:27017", "pesquisa_cms_store_duplicado" ); //string Result4 = Runner4.GetJSON( Query4 ); //QueryRunner Runner5 = new QueryRunner( "mongodb://localhost:27017", "pesquisa_cms_user_duplicado" ); //string Result5 = Runner5.GetJSON( Query5 ); JToken ResultJson = JToken.Parse(Result); JToken ResultJson2 = JToken.Parse(Result2); //JToken ResultJson3 = JToken.Parse( Result3 ); //JToken ResultJson4 = JToken.Parse( Result4 ); //JToken ResultJson5 = JToken.Parse( Result5 ); }
public override void ExitQuery([NotNull] QueryBuilderQueriesParser.QueryContext context) { QueryableEntity qEntity = context.entity().qEntity; StartArg = getStartArg(qEntity); List <RelationshipJoinOperator> rjoinOps = getRelationshipJoinOperators(qEntity); rjoinOps.ForEach(rjo => PipelineOperators.Add(rjo)); if (ProjectOp != null) { PipelineOperators.Add(ProjectOp); } if (context.where () != null) { SelectStage2 SelectOp = new SelectStage2(); SelectOp.LogicalExpression = getLogicalExpression(context.where ().logicalExpression()); PipelineOperators.Add(SelectOp); } }
public virtual List <TEntity> GetWhereAsNoTracking(Func <TEntity, bool> predicate) { return(QueryableEntity.AsNoTracking()?.Where(predicate).ToList()); }
public virtual List <TEntity> GetWhere(Func <TEntity, bool> predicate) { return(QueryableEntity.Where(predicate).ToList()); }
public virtual Task <List <TEntity> > GetWhereAsync(Func <TEntity, bool> predicate) { return(Task.Run(() => QueryableEntity.Where(predicate).ToList())); }
public virtual List <TEntity> GetAll() { return(QueryableEntity.ToList()); }
public virtual Task <List <TEntity> > GetAllAsync() { return(QueryableEntity.ToListAsync()); }
public virtual Task <bool> ContainsAsync(TEntity entity) { return(Task.Run(() => QueryableEntity.FirstOrDefault(p => p.Id.Equals(entity.Id)) != null)); }
public virtual bool Any(Func <TEntity, bool> predicate) { return(QueryableEntity.Any(predicate)); }
public virtual TEntity GetFirst(Func <TEntity, bool> predicate) { return(QueryableEntity.First(predicate)); }
public IQueryable <TEntity> Include(string path) { return(QueryableEntity.Include(path)); }
public virtual TEntity GetSingleOrDefault(Func <TEntity, bool> predicate) { return(QueryableEntity.SingleOrDefault(predicate)); }
public Task <TEntity> FindByIdAsync(TKey id) { return(QueryableEntity.FirstOrDefaultAsync(p => p.Id.ToString().Equals(id.ToString()))); }
public virtual List <TEntity> GetWhereAsNoTracking <TProperty>(Expression <Func <TEntity, TProperty> > includePredicate, Func <TEntity, bool> predicate) { return(QueryableEntity.AsNoTracking().Include(includePredicate).Where(predicate).ToList()); }