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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:12:02+00:00 2026-06-14T18:12:02+00:00

I created my database via EF, and now (using LINQ) I want to return

  • 0

I created my database via EF, and now (using LINQ) I want to return a list (called posts) where it is linked to its optional list (called flags)

In the example below, you can see I give table Post a virtual List of flags (which means optional right?)

MODEL :

public class Post
{
    public int PostID { get; set; }
    public string Title { get; set; }
    public DateTime? Dateapproved { get; set; }
    public virtual List<Flag> Flags { get; set; }
}

public class Flag
{
    public int FlagID { get; set; }
    public int PostID { get; set; }
}

EF :

public class sampleProject : DbContext
{
    public DbSet<Post> Posts { get; set; }
    public DbSet<Flag> Flags { get; set; }
}

How would I get a list of Posts where there is a link to flags, and Dateapproved is not null?

Ofcourse this won’t work, because the declaration is expecting a Post, and is getting a list of flags instead :

List<Post> postlist = context.Flags.Where(x => x.Post.DateApproved != null).ToList();

I know of the “Include” function, but not sure it will work here

What is the best practice here?
Should I split it somehow into more steps?

  • 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-14T18:12:03+00:00Added an answer on June 14, 2026 at 6:12 pm

    How would I get a list of Posts where there is a link to flags, and
    Dateapproved is not null?

    Try this:

    var posts = db.Posts.Include("Flags").Where(x => x.Flags.Any() && x.Dateapproved != null).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a web system using Java Servlets and now want to make
I have a Microsoft Access 2010 database(*). Now, using Visual Studio 2010, I want
I have created a simple windows service that periodically checks a remote database via
I recently created my simple log4net database table for logging via the adonet appender..
I successfully created database on my local server using Code First, migrated it to
iv created a database with some tables and populated them using SQL server 2008,
I created a database for a site i'm doing using Django as the admin
Using osql command, SSQL backup of a database is created. It is saved to
I have an SQLite database file, created using Sqliteman admin utility. I copied the
I have initialy created a changeset which loads(via loadData) countries into my database if

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.