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

The Archive Base Latest Questions

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

I’ve got three classes. Event > Workshop > Workshop Times I’m currently looking for

  • 0

I’ve got three classes.

Event > Workshop > Workshop Times

I’m currently looking for best way of inserting records into the Workshop Times, this is running through code first using ICollections.

Looking for something along the lines of this, but I know it doesn’t work:

       //Create connection
        var db = new Context();

        var Event = db.Events
            .Include("Workshops")
            .Include("Workshops.Times")
            .Where(ev => ev.GUID == EventGUID).FirstOrDefault();

        Event.Workshops.Add(new Workshop
        {
            Name = tbWorkshopName.Text,
            Description = tbWorkshopDescription.Text,
            Times.Add(new WorkshopTime{
                //Information for times
            })
        });

        db.SaveChanges();

Chopped down classes:

public class Workshops{
    public int id { get; set; }
    public string name { get; set; }
    public ICollection<WorkshopTimes> Times{get;set;}
}
public class Events {
    public int id { get; set; }
    public string name { get; set; }
    public ICollection<Workshops> WorkShops { get; set; }
}

public class WorkshopTimes {
    public int id { get; set; }
    public DateTime time { get; set; }
}
  • 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-14T19:09:27+00:00Added an answer on June 14, 2026 at 7:09 pm

    You are definitely on the right track with your query, however your include statements appear incorrect. From your model I would expect:

        var Event = db.Events
            .Include("WorkShops")
            .Include("WorkShops.events")
            .Where(ev => ev.GUID == EventGUID).FirstOrDefault();
    

    Note this uses the property names not the types. This will ensure that the entities in the listed nav properties will be included in the result.

    In addition you can use a lambda to do the same thing (but its typesafe)

    Check out here for how to do a very similar scenario to yours:

    EF Code First – Include(x => x.Properties.Entity) a 1 : Many association

    or from rowan miller (from EF team)

    http://romiller.com/2010/07/14/ef-ctp4-tips-tricks-include-with-lambda/

    And make sure you are using System.Data.Entities for lambda based includes ( Where did the overload of DbQuery.Include() go that takes a lambda? )

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.