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

  • Home
  • SEARCH
  • 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 92763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:14:18+00:00 2026-05-10T23:14:18+00:00

I am having some issues with using the OrderBy extension method on a LINQ

  • 0

I am having some issues with using the OrderBy extension method on a LINQ query when it is operating on an enum type. I have created a regular DataContext using visual studio by simply dragging and dropping everything onto the designer. I have then created seperate entity models, which are simply POCO’s, and I have used a repository pattern to fetch the data from my database and map them into my own entity models (or rather, I have a repository pattern, that builds up and IQueryable that’ll do all this).

Everything works just fine, except when I try to apply an OrderBy (outside of the repository) on a property that I have mapped from short/smallint to an enum.

Here are the relevant code bits:

public class Campaign {     public long Id { get; set; }     public string Name { get; set; }     ....     public CampaignStatus Status { get; set; }     ... } public enum CampaignStatus : short {     Active,     Inactive,     Todo,     Hidden } public class SqlCampaignRepository : ICampaignRepository { ...     public IQueryable<Campaign> Campaigns()     {         DataContext db = new DataContext();         return from c in db.Campaigns                 select new Campaign                    {                        Id = c.Id,                        Name = c.Name,                        ...                        Status = (CampaignStatus)c.Status,                        ...                    };      } } 

And then elsewhere

SqlCampaignRepository rep = new SqlCampaignRepository(); var query = rep.Campaigns().OrderBy(c => c.Status); 

This triggers the following exception: System.ArgumentException was unhandled by user code Message=’The argument ‘value’ was the wrong type. Expected ‘IQMedia.Models.CampaignType’. Actual ‘System.Int16′.’ Source=’System.Data.Linq’ StackTrace: ved System.Data.Linq.SqlClient.SqlOrderExpression.set_Expression(SqlExpression value) ved System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitSelect(SqlSelect select) ved System.Data.Linq.SqlClient.SqlVisitor.Visit(SqlNode node) ved System.Data.Linq.SqlClient.SqlBinder.Visitor.VisitIncludeScope(SqlIncludeScope scope) …

(sorry about the danish in there, ved = by/at).

I have tried typecasting the Status to short in the orderBy expression, but that doesn’t help it, same if i cast it to the actual enum type as well.

Any help fixing this is greatly appreciated!

  • 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. 2026-05-10T23:14:19+00:00Added an answer on May 10, 2026 at 11:14 pm

    Can you specify the type CampaignStatus directly in your DataContext trough the designer? This way the value is automatically mapped to the enum.

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

Sidebar

Ask A Question

Stats

  • Questions 168k
  • Answers 168k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need a table for Orders, a table for Pizzas… May 12, 2026 at 1:45 pm
  • Editorial Team
    Editorial Team added an answer One quick a dirty approach would be to use <%… May 12, 2026 at 1:45 pm
  • Editorial Team
    Editorial Team added an answer You aren't really. Linq loads the objects as you need… May 12, 2026 at 1:45 pm

Related Questions

I am having some issues with Microsoft Explorer 6/7 and the jQuery clone function.
I am having some issues with managers, because they believe that (intuitively) creating desktop
I draw two spheres in 3d WPF which has points like Point3D(0,0,0) and Point3D(-1.0,1.0,2.0)
Ok I am still having some issues with this code below. I have received

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.