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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:54:58+00:00 2026-05-16T05:54:58+00:00

I have a table that has two records (there will be many at runtime).

  • 0

I have a table that has two records (there will be many at runtime). The deviceId of the records are, “DEVICE1” and “DEVICE2”. I want to use a regular expression to extract records.

The code below compiles but fails to return a result. When I hover the cursor on the “devices.ToList()” statement I get the following error:

base {System.SystemException} = {"LINQ to Entities does not recognize the method 'System.Text.RegularExpressions.MatchCollection Matches(System.String)' method, and this method cannot be translated into a store expression."}”

Can anyone show me how I can modify my query so that this would return records based on the expression?

filterText = @"DEVICE.";
Regex searchTerm = new Regex(filterText);

using (var ctx = new MyEntities())
{
 var devices = from d in ctx.Devices
                let matches = searchTerm.Matches(d.DeviceId)
                where matches.Count > 0
                select ((Device)d);
return devices.ToList();
}
  • 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-05-16T05:54:59+00:00Added an answer on May 16, 2026 at 5:54 am

    I don’t believe you can use regular expressions with LINQ to Entities. However, it looks like you’re just trying to find devices which start with “DEVICE”, so the query would be:

    return ctx.Devices.Where(d => d.DeviceId.StartsWith("DEVICE"))
                      .ToList();
    

    EDIT: If you actually need the flexibility of a regular expression, you should probably first fetch the device IDs (and only the device IDs) back to the client, then perform the regular expression on those, and finally fetch the rest of the data which matches those queries:

    Regex regex = new Regex(...);
    
    var deviceIds = ctx.Devices.Select(d => DeviceId).AsEnumerable();
    
    var matchingIds = deviceIds.Where(id => regex.IsMatch(id))
                               .ToList();
    
    var devices = ctx.Devices.Where(d => matchingIds.Contains(d.DeviceId));
    

    That’s assuming it would actually be expensive to fetch all the data for all devices to start with. If that’s not too bad, it would be a simpler option. To force processing to be performed in process, use AsEnumerable():

    var devices = ctx.Devices.AsEnumerable()
                             .Where(d => regex.IsMatch(d.DeviceId))
                             .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that has two datetime columns (one for start time and
I have one table that has two fields - ID1 and ID2 ID1 can
I have a table that has two columns: CommunityID PersonID And A People table
I have a city table that has two columns from_city to_city now lets assume
I have a table, myTable that has two fields in it ID and patientID
I have created a table in Visual Studio. That table has two columns. First
I have a table, tblNoComp, that has two columns, both foreign keys pointing to
I have a large table (~1M rows now, soon ~10M) that has two ranked
I have a table that has about 1/2 million records in it. Each month
I have two tables: object that has object_id column and avalues that have object_id

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.