Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8583339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:30:44+00:00 2026-06-11T21:30:44+00:00

I have a simple class: public class User : ActiveRecordLinqBase<User> { [PrimaryKey(Column = user_id,

  • 0

I have a simple class:

public class User : ActiveRecordLinqBase<User>
{
    [PrimaryKey(Column = "user_id", Length = 20)]
    public string Id { get; set; }

    [Property(Column = "password", Length = 16)]
    public string Password { get; set; }
    ...
}

and I have created the following repository:

public class SqlRepository<T> : IRepository<T> where T : ActiveRecordLinqBase<T>, new() {
    public void Add(T entity) {
        entity.SaveAndFlush();
    }

    public void Remove(T entity) {
        entity.DeleteAndFlush();
    }

    public void Modify(T entity) {
        entity.UpdateAndFlush(); ;
    }

    ...

    public IEnumerable<T> FindAll(Func<T, bool> predicate) {
        return ActiveRecordLinqBase<T>.Queryable.Where(predicate);
    }
}

Now, when running the following unit test (against a MySQL database):

[Test]
public void Test_Sample() {
    var repo = new SqlRepository<T>();
    repo.Add("john.doe", "keyword1");
    repo.Add("other.user", "keyword2");

    var users = repo.FindAll(x => x.Username.Contains("john")).ToList();

    Assert.AreEqual(1, users.Count);
}

… I get the following SQL query:

SELECT this_.user_id as user1_0_0_, this_.password as password0_0_, this_.role as role0_0_ FROM users this_

Where is the WHERE clause?

If I instead do the following in the same test directly…

var users = User.Queryable.Where(x => x.Username.Contains("john"));

I get the following SQL:

SELECT this_.user_id as user1_0_0_, this_.password as password0_0_, this_.role as role0_0_ FROM users this_ WHERE this_.user_id like ?p0;?p0 = ‘%john%’

Am I doing something wrong?

What is the difference between those two queries?


Edit: I also tried with

return ActiveRecordLinq.AsQueryable<T>().Where(predicate);

without success.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:30:45+00:00Added an answer on June 11, 2026 at 9:30 pm

    Now this is just because I like code, and sometimes I notice stuff… I’m no expert on Active Record, so this is just a guess…

    Maybe you should change the signature of the FindAll method from

    public IEnumerable<T> FindAll(Func<T, bool> predicate)
    

    into

    public IEnumerable<T> FindAll(Expression<Func<T, bool>> predicate)
    

    which will allow you to hit the right overload of Where, which is most likely the overload you’re looking for.

    It’s because a Func can’t be reflected upon the same way an Expression of Func can.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a simple Java class like this: public class User { String
I have simple POJO say User Object; public class User{ private String userid; private
I have an simple class that I get from a webservice. public class person
I have simple type Question : public class Question { public string[] Tags {
I have a simple object public class SomeObject { public Int32 id { get;
I have, let's say, this simple class: public class User { [Required(AllowEmptyStrings = false,
I have simple controller: public class TestController : Controller { public ActionResult Test(string r)
I have two classes: public class Reference { public virtual string Id { get;
I have a simple object like this public class Test { public string Name
I have pretty simple JAX-RS WS: @Stateless @Path(/foo) public class FooFacadeBean { @GET @Produces(MediaType.TEXT_HTML)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.