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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:02:55+00:00 2026-05-25T16:02:55+00:00

I have this schema: …and I want to select some records using this query:

  • 0

I have this schema:

enter image description here

…and I want to select some records using this query:

SELECT
    Articles.ArticleId,
    Articles.Title, 
    Articles.Tooltip, 
    Articles.UriTitle, 
    Articles.SubTitle, 
    Articles.Published,
    Tags.TagId
FROM Articles INNER JOIN
     ArticleTag ON Articles.ArticleId = ArticleTag.ArticleId INNER JOIN
         Tags ON ArticleTag.TagId = Tags.TagId
WHERE (Tags.TagId = @tagid) AND (Articles.Published = 1)

Can anybody help me to convert this query to EF 4.1 Code First (a lambda expression) please?

UPDATE:

I use @Ladislav Mrnka code (as a lambda expression) and code works! Now I put generated sql here, and check it please to ensure there is no problem:

// C#:
var query = context.Articles.Where(a => a.Published && a.Tags.Any(t => t.TagId == tagId))
                            .Select(a = new {
                                a.ArticleId,
                                a.Title,
                                a.Tooltip,
                                a.UriTitle,
                                a.SubTitle,
                                a.Published
                            });

and the generated sql is

SELECT 
[Extent1].[ArticleId] AS [ArticleId], 
[Extent1].[Title] AS [Title], 
[Extent1].[Tooltip] AS [Tooltip], 
[Extent1].[UriTitle] AS [UriTitle], 
[Extent1].[SubTitle] AS [SubTitle], 
[Extent1].[Description] AS [Description], 
[Extent1].[Keywords] AS [Keywords], 
[Extent1].[MetaDescription] AS [MetaDescription], 
[Extent1].[CreatedAt] AS [CreatedAt], 
[Extent1].[UpdatedAt] AS [UpdatedAt], 
[Extent1].[Viewed] AS [Viewed], 
[Extent1].[Published] AS [Published], 
[Extent1].[Body] AS [Body]
FROM [dbo].[Articles] AS [Extent1]
WHERE ([Extent1].[Published] = 1) AND ( EXISTS (SELECT 
    1 AS [C1]
    FROM [dbo].[ArticleTag] AS [Extent2]
    WHERE ([Extent1].[ArticleId] = [Extent2].[ArticleId]) AND ([Extent2].[TagId] = @p__linq__0)
))
  • 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-25T16:02:56+00:00Added an answer on May 25, 2026 at 4:02 pm

    Try:

    int tagId = ...;
    var query = from a in context.Articles
                where a.Tags.Any(t => t.TagId == tagId) && a.Published 
                select new 
                   {
                       a.ArticleId,
                       a.Title,
                       a.Tooltip,
                       a.UriTitle,
                       a.SubTitle,
                       a.Published,
                       tagId // I'm not sure if this will work but let give it a try  
                   };
    

    If selecting TagId doesn’t work it is not too big problem because you know that all records have same tag Id.

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

Sidebar

Related Questions

I have an Oracle account (schema) of a remote Oracle database. By using this
I have this schema and i'm using JAXB to generate java stub files. <?xml
I have this kind of db:schema : articles +-------+ article_users +------+ user How can
I have this schema: http://img602.imageshack.us/img602/6978/schemac.png I want to insert an Order with OrderItems into
I have xsd file. I want to generate my entity model from this schema
I have this query: SELECT p.prodno AS id, proddesc AS label FROM product p
I'm new to Solr. Using Solr 1.4.1 I have a schema.xml that have this
I have this schema: <xs:complexType name=foo> <xs:sequence> <xs:element name=oneBar type=xs:string minOccurs=0/> <xs:element name=twoBar type=xs:string
I have this schema which I need to match 2 rows from user_data :
Say I have this table schema. ID AccNo Amount Say I have this data

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.