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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:43:54+00:00 2026-06-15T13:43:54+00:00

I have a many-to-many relationship in my code and I am trying to seed

  • 0

I have a many-to-many relationship in my code and I am trying to seed the database. Here is my seed method:

var loc = new List<Location> {
      new Location { LocationName = "Paradise Lane" },
      new Location { LocationName = "81st Street" }
};
loc.ForEach(l => context.Locations.Add(l));


var soft = new List<Software> {
     new Software { Title = "Adobe Creative Suite", ... Locations = loc.Single(s => s.LocationName = "Paradise Lane")}
};
soft.ForEach(s => context.Software.Add(s));

Here is my locations class:

public class Location
    {
        public int Id { get; set; }
        [Required]
        [StringLength(20)]
        public string LocationName { get; set; }
        public virtual ICollection<Software> Software { get; set; }
    }

Here is my software class:

public class Software
    {
        public int Id { get; set; }
        [Required]
        [StringLength(128)]
        public string Title { get; set; }
        [Required]
        [StringLength(10)]
        public string Version { get; set; }
        [Required]
        [StringLength(128)]
        public string SerialNumber { get; set; }
        [Required]
        [StringLength(3)]
        public string Platform { get; set; }
        [StringLength(1000)]
        public string Notes { get; set; }
        [Required]
        [StringLength(15)]
        public string PurchaseDate { get; set; }
        public bool Suite { get; set; }
        public string SubscriptionEndDate { get; set; }
        //[Required]
        //[StringLength(3)]
        public int SeatCount { get; set; }
        public virtual ICollection<Location> Locations { get; set; }
        public virtual ICollection<SoftwarePublisher> Publishers { get; set; }
        public virtual ICollection<SoftwareType> Types { get; set; }

    }

I am getting two errors. One, it tells me I cannot implicitly convert string to bool. I didn’t even know I was trying to do t hat. And two, cannot convert lambda express to delegate because soem fo the return types in the block are not implicitly convertable to the delegate return type. Is that a reference to the iCollection?

  • 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-15T13:43:55+00:00Added an answer on June 15, 2026 at 1:43 pm

    You missed an equals sign. Double equals for comparing.

    loc.Single(s => s.LocationName = "Paradise Lane")
    

    vs

    loc.Single(s => s.LocationName == "Paradise Lane")
    

    Also, you can’t do a .Single() into Locations because it is an ICollection. Single returns 1 object, not a collection. You should use .Where instead. Or you can implicitly declare an array in there and use your .Single() code inside it.

    Edit: Also apparently .Where() doesn’t cast nicely to ICollection. Add a ToArray and you’ll get an array which is acceptable.

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

Sidebar

Related Questions

I am new to EF, and trying to get many-to-many unidirectional relationship with code
I'm using EF 4.3 code-first. I have a many-to-many relationship. I am trying in
So I'm trying to fetch data in a many-to-many relationship. So far I have
New to rails and trying to get a one to many relationship up and
I'm trying to do a many-many database select, where I have events and music
I have a many-to-many relationship between Recipes and Ingredients . I am trying to
I'm trying to create a many-to-many relationship using EF code first in my MVC
I'm working with EF4.1 Code First and am trying to create some Many-to-Many relationship
I am trying to build a relationship to another many-to-many relationship, the code looks
I have many to many relationship in entity framework. See image... I want to

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.