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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:41:01+00:00 2026-05-25T17:41:01+00:00

I use c# and ef4. I have a Model with an Entity with two

  • 0

I use c# and ef4.

I have a Model with an Entity with two proprieties int Id and string Title.

I need to write an ESQL query that is able to return bool TRUE if Id and Title are present in the DataSource. Please note Id is a PrimaryKey in my data storage.

Any idea how to do it?

  • 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-25T17:41:01+00:00Added an answer on May 25, 2026 at 5:41 pm

    You can do it by each code-snippets below:


    1)

    using (YourEntityContext context = new YourEntityContext ()) {
        var queryString = 
            @"SELECT VALUE TOP(1) Model FROM YourEntityContext.Models 
                  As Model WHERE Model.Id = @id AND Model.Title = @title";
        ObjectQuery<Model> entityQuery = new ObjectQuery<Model>(queryString, context);
        entityQuery.Parameters.Add(new ObjectParameter("id", id));
        entityQuery.Parameters.Add(new ObjectParameter("title", title));
        var result = entityQuery.Any();
    }
    

    2)

    using (YourEntityContext context = new YourEntityContext ()) {
        ObjectQuery<Model> entityQuery = 
            context.Models
            .Where("it.Id = @id AND it.Title = @title"
                , new ObjectParameter("id", id)
                , new ObjectParameter("title", title)
            );
        var result = entityQuery.Any();
    }
    

    3)

    var context = new YourEntityContext();
    using (EntityConnection cn = context.Connection as EntityConnection) {
        if (cn.State == System.Data.ConnectionState.Closed)
            cn.Open();
        using (EntityCommand cmd = new EntityCommand()) {
            cmd.Connection = cn;
            cmd.CommandText = @"EXISTS(
                                    SELECT M FROM YourEntityContext.Models as M 
                                    WHERE M.Id == @id AND Model.Title = @title
                               )";
            cmd.Parameters.AddWithValue("id", _yourId);
            cmd.Parameters.AddWithValue("title", _yourTitle);
            var r = (bool)cmd.ExecuteScalar();
        }
    }
    

    4)

    using (YourEntityContext context = new YourEntityContext ()) {
        var queryString = 
            @"EXISTS(
                  SELECT M FROM YourEntityContext.Models as M 
                  WHERE M.Id == @id AND Model.Title = @title
              )";
        ObjectQuery<bool> entityQuery = new ObjectQuery<bool>(queryString, context);
        entityQuery.Parameters.Add(new ObjectParameter("id", id));
        entityQuery.Parameters.Add(new ObjectParameter("title", title));
        var result = entityQuery.Execute(MergeOption.AppendOnly).FirstOrDefault();
    }
    

    4 is the best way I suggest you. Good lock

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

Sidebar

Related Questions

I use c#, linq and EF4. I need help to write a LINQ query
I use c#, linq and EF4. I have two tables in my DataBase represented
I use c#, linq and EF4. I have two tables in my DataBase represented
New to Entity Framework .Using EF4. I have found articles and managed to use
I use c#, linq and EF4. I have two tables in my DataBase represented
I have an entity model build using EF4.1 code first, which uses a WCF
I have a query that returns a resultset. And I want to apply filter
I am creating a model with EF4.1 CodeFirst. I use: Database.SetInitializer(Of dbModel.dbDB2Data)(New DropCreateDatabaseIfModelChanges(Of dbModel.dbDB2Data))
I use asp.net 4 c# and ef4. I have this code, it should compile
I am using EF 4 and have the following code. public static Dictionary<Tuple<int, string>,

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.