Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

I have two models and first model has a property ICollection. I have one to many relationship between them and I defined that using fluent

I have two models and first model has a property ICollection. I have one to many relationship between them and I defined that using fluent API (using entity framework). But in SQL server I am only seeing first model's table populate with data. The second model's table does not populate as I insert data. Here is more details:

Model 1:

public class Model1{

public int? PersonId { get; set; } public string LastName { get; set; } public string FirstName { get; set; }

public virtual ICollection model2 { get; set; }

}

Model 2:

public class Model2{

public int? Id { get; set; } public int PersonId { get; set; } public int number { get; set; }

}

Fulent API:

modelBuilder.Entity().HasMany(x => x.model2).WithRequired();

I have a feeling I am supposed to put something inside WithRequired()?

why is the table for not populating?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students explore these related Databases questions

Question

What did they do? What did they say?

Answered: 3 weeks ago