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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:35:16+00:00 2026-06-04T02:35:16+00:00

Long story short I need to get items based on a range (high/low value),

  • 0

Long story short I need to get items based on a range (high/low value), however the column/property from the database is a string and I’m not allowed to change that. So how am I supposed to compare a range?

I can’t seem to find a way to convert the entity property to an int so i can compare.
Of course Convert.toInt32 doesn’t work either. I don’t see any SqlFunctions that will help but maybe I’m overlooking something easy.

I’ve been playing with it, but so far no luck. This is my latest try that doesn’t work:

var result = Repo.Query().Where(e => e.SerialNumber.Cast<int>().First() >= myIntLowVariable && e.SerialNumber.Cast<int>().First() <= myIntHighVariable);

Any suggestions?

Update

The user enters two SerialNumbers and I need to return all the records in that range, however SerialNumber is a string/varchar column/property.

Data – Sorry no idea how to put a table in here..

SN :: Description
1 :: Milk
2 ::Eggs
3 :: Bread
4 :: Cheese
5 :: Bacon
6 :: Yogurt
7 :: Mustard
8 :: Chicken
9 :: Pizza
10 :: Chips

  • 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-04T02:35:18+00:00Added an answer on June 4, 2026 at 2:35 am

    If you call ToList() on your query then you should be able to cast your string to Int32.

    var result = Repo.Query().ToList().Where(e => e.StringNumberField.Cast<int>().First() >= myIntLowVariable && e.StringNumberField.Cast<int>().First() <= myIntHighVariable);
    

    If you cannot project the entire query then you can do the following:

    Create a stored procedure in you db that does the filtering. Something like this will do:

    CREATE PROCEDURE spGetStuffBetween
    (
        @min int,
        @max int
    )
    AS
    BEGIN
        SELECT * from dbo.Stuff where Convert(int, SerialNumber) < @max and  Convert(int, SerialNumber) > @min;
    END
    

    Update your model from the database with the newly-added stored procedure using the EDM tools. Under ‘Add’, select the stored procedure you just created and select ‘Finish’.

    After you have updated your Model you will not be able to see the stored procedure so right-click on the design surface and select ‘Model Browser’. You will be able see it under the Stored Procedures node.

    Double-click on the stored procedure in the Model Browser. Here you can specify the type of collection you are returning from the stored procedure.

    Now you can call the following code to get the results that you want:

    int myIntLowVariable = 1000;
    int myIntHighVariable = 1000000;
    
    var results= Repo.spGetAnimalsBetweenRange(myIntLowVariable , myIntHighVariable );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long story short, I need to get up to speed with Joomla fast .
Long story short, I need to get the total scroll size for a text
Long story short, client's hosting is using php 5.2.5 and i desperately need to
So long story short, i have some forms (2) of them that, need different
Long story short, the database I'm using needs to get looked at. Until that
To keep the long story short, I am unable to use the container from
Long story short - In order to make something work correctly, I need to
There are a few things I need help understanding. Long story short: Client has
Long story short, I need to sort an array of objects using usort, and
Long story short, I have a substantial Python application that, among other things, does

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.