Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Søren Kottal 712 posts 4550 karma points MVP 6x c-trib
    Jul 13, 2016 @ 10:02
    Søren Kottal
    0

    Fetch from custom sql where id is in array

    Hi

    Trying to do some custom sql magic. Currently have this:

            var classSql = new Sql()
                .Select("*")
                .From<SchoolClass>(_syntax)
                .Where<SchoolClass>(x => x.MemberId == id)
                .OrderBy<SchoolClass>(x => x.Name, _syntax);
    
            var schoolClasses = _db.Fetch<SchoolClass>(classSql);
            var schoolIds = schoolClasses.Select(x => x.SchoolId).Distinct();
    
            var schoolSql = new Sql()
                .Select("*")
                .From<School>(_syntax)
                .Where<School>(x => schoolIds.Contains(x.Id))
                .OrderBy<School>(x => x.Name, _syntax);
    
            var schools = _db.Fetch<School>(schoolSql);
    

    But it gives me an exception

    variable 'x' of type 'MyProject.Pocos.School' referenced from scope '', but it is not defined
    

    I am trying to fetch all the schools from the schoolClasses.

    Whats wrong?

  • Søren Kottal 712 posts 4550 karma points MVP 6x c-trib
    Jul 13, 2016 @ 10:44
    Søren Kottal
    100

    Found out, I need to use .WhereIn instead of .Where

Please Sign in or register to post replies

Write your reply to:

Draft