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 7747007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:25:25+00:00 2026-06-01T10:25:25+00:00

This is probably a relatively simple oversight, but I can’t work out if I’m

  • 0

This is probably a relatively simple oversight, but I can’t work out if I’m actually allowed to do this, or what might be a reasonable alternative (using in VS2010, C# .Net 4.0). I would strongly prefer to do this in the constructor if at all possible.

This is my class:

public class MyClass1<TOrderBy> : MyInterface1<MyType1, MyType2>
{
    public MyClass1(IEnumerable<Guid> ids) : this(ids, 0, 10, a => a.Time, ListSortDirection.Ascending) { }

    public MyClass1(IEnumerable<Guid> ids, int pageIndex, int itemsPerPage, Expression<Func<MyType2, TOrderBy>> orderBy, ListSortDirection sortDirection)
        {
            this.pageIndex = pageIndex;
            this.itemsPerPage = itemsPerPage;
            this.orderBy = orderBy;
            this.sortDirection = sortDirection;
            this.ids = ids != null ? ids.ToList() : new List<Guid>();
        }
}

I get the error

Cannot convert expression type 'System.DateTime' to return type 'TOrderBy' when hovering over a => a.Time

and the errors Cannot convert lambda expression to delegate type 'System.Func<MyType2,TOrderBy>' because some of the return types in the block are not implicitly convertible to the delegate return type and Cannot implicitly convert type 'System.DateTime' to 'TOrderBy' when building.

As you can probably work out, I’m trying to build a class that takes information in the constructor to sort and page an IQueryable.
I want to supply defaults via overloaded constructors. How would I go about doing this?

  • 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-01T10:25:26+00:00Added an answer on June 1, 2026 at 10:25 am
    a => a.Time
    

    Time is a DateTime. TOrderBy might not be a DateTime, for example:

    MyClass1<Car> x = new MyClass1<Car>(ids);
    

    So, you can’t do what you’re trying to do.


    That TOrderBy is a big pain! The best idea would be to avoid the problem by not having a TOrderBy as part of the class if you can help it. This answer shows a way to wrap the ordering expression to hide the TOrderBy from the outside world.

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

Sidebar

Related Questions

I found out really strange behavior on relatively simple use case, probably I can't
This is probably a simple question for you JAVA experts, but I'm relatively new,
This is probably something simple, but I can't seem to find the answer. I
I know this probably really simple but Im not sure what im doing wrong...
The question probably sounds a little odd, but the actual task is relatively simple,
I'm relatively new to sql so this may probably come off as a simple
I'm aware this is probably a very simple problem with a 1-line-of-code answer but
I'm relatively new to node.js and it's addons, so this is probably a beginnersquestion.
This probably sounds like a terrible idea at first glance, but here is my
This probably is a dummy question but I cannot find a clear indication. I

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.