Skip to content

Latest commit

 

History

History
26 lines (24 loc) · 1.25 KB

Query.md

File metadata and controls

26 lines (24 loc) · 1.25 KB

Query and Expression

Lets build a select expression here and see how it works

   using (var rep = new Repository())
   {
        // LoadChildren indicates that it will load the children hierarchy.
        // It has no problem handling circular references.
        // The query does not call to the database before we invoke Execute or ExecuteAsync
        var users = rep.Get<User>().Where(x => 
                (x.Role.Name.EndsWith("SuperAdmin") &&
                 x.UserName.Contains("alen")) ||
                 x.Address.Any(a=> a.AddressName.StartsWith("st"))
                ).LoadChildren().Execute(); 
                
        // lets say that we need only to load some children and ignore some other, then our select will be like this instead
          var users = rep.Get<User>().Where(x => 
                (x.Role.Name.EndsWith("SuperAdmin") &&
                 x.UserName.Contains("alen")) ||
                 x.Address.Any(a=> a.AddressName.StartsWith("st"))
                ).LoadChildren(x=> x.Role.Users.Select(a=> a.Address), x=> x.Address)
                .IgnoreChildren(x=> x.Role.Users.Select(a=> a.Role)).OrderBy(x=> x.UserName).Skip(20).Take(100).Execute();        
        Console.WriteLine(users.Json());
        Console.ReadLine();
   }