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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:09:05+00:00 2026-06-12T19:09:05+00:00

We need to create dynamic WHERE Clauses depending on user input. Using the old

  • 0

We need to create dynamic WHERE Clauses depending on user input.
Using the old ObjectContext we found a way by using .Where(<ESql>).

Dim qry As ObjectQuery(Of MESSGROESSE) = _objContext.MESSGROESSE
If Not String.IsNullOrWhiteSpace(fltFormelzeichen.Text) Then
    qry = qry.Where("it.Formelzeichen LIKE @Formelzeichen", New ObjectParameter("Formelzeichen", BuildESqlWildCard(fltFormelzeichen.Text)))
End If
If Not String.IsNullOrWhiteSpace(fltBezeichnung.Text) Then
    qry = qry.Where("it.Bezeichnung LIKE @Bezeichnung", New ObjectParameter("Bezeichnung", BuildESqlWildCard(fltBezeichnung.Text)))
End If

Because this is a new project we would like to generally use the new DbContext. I know how to get at the ObjectContext from a DbContext:

Private _objContext As ObjectContext = CType(_dbContext, IObjectContextAdapter).ObjectContext

But then what?

Using DbContext.Database.SqlQuery or ObjectContext.CreateQuery seems not to be an option, option because the EDMX generator destroys column names if they are the same as the table name and we do not have control over the DB schema. See How to stop the EDMX generator from changing columns names.

We do not want dependencies on open source solutions.

ADDED

Meanwhile I talked the customer out of needing wildcards, so we can use Contains() with dbConctext:

_dbc = New TPTEntities
Dim qry As DbQuery(Of MESSGROESSE) = _dbc.MESSGROESSE
qry = From e In _dbc.MESSGROESSE Take maxRows

If Not String.IsNullOrWhiteSpace(fltFormelzeichen.Text) Then
    qry = From e In qry Where e.FORMELZEICHEN.Contains(fltFormelzeichen.Text)
End If
If Not String.IsNullOrWhiteSpace(fltBezeichnung.Text) Then
    qry = From e In qry Where e.BEZEICHNUNG.Contains(fltBezeichnung.Text)
End If
If Not String.IsNullOrWhiteSpace(fltReihenfolge.Text) Then
    qry = From e In qry Where e.REIHENFOLGE = fltReihenfolge.Text
End If
qry.Load()
'TODO is _dbc.MESSGROESSE.Local the correct way to get at the data here?
ucoGridEditor.grd.ItemsSource = _dbc.MESSGROESSE.Local

I would still like to know how to use ESql Where() on dbContext though.

  • 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-12T19:09:07+00:00Added an answer on June 12, 2026 at 7:09 pm

    DbContext is built on top of ObjectContext. You can drop to ObjectContext by using:

    var objectContext = ((IObjectContextAdapter)ctx).ObjectContext;
    

    where ctx is your DbContext (derived) class.

    There is an alternative to use esql though. You could build expression trees dynamically. Take a look at this thread EF object comparison with generic types – the code shows how to build a filter expression dynamically.

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

Sidebar

Related Questions

I need to create dynamic menu using and submenu using dynamically using c# code
I am looking for a way to create dynamic preferences where I don't need
I need to create dynamic INNER JOIN (I believe I need to anyway). I
I need to create some dynamic menus in a VS2010 SDI application I'm writing.
I need to create a dynamic array in Java, but the values type differ
I need to create a real dynamic JPA CriteriaBuilder . I get an Map<String,
I am trying to create a dynamic UI using UpdatePanel of AJAX toolkit. Let
I'm using GeoChart from the Google Visualisation API to create a dynamic map containing
Possible Duplicate: Need help in dynamic query with IN Clause I am using SQL
When you need Dynamic WHERE Clause I can use; CREATE PROCEDURE [dbo].[sp_sel_Articles] @articleId INT

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.