I am using Database First approach to create models from existing database. I have two entities, say A and B. Entity A can hold a collection of Entity B, so in the model class for entity A, it has a ICollection of entity B and it is instantiated in entity A’s constructor as below:
class A
{
public A()
{
this.Bs = new HashSet<B>();
}
public virtual ICollection<B> Bs { get; set; }
}
Now, I want to retrieve the collection of B for the given A. How would I do that?
Say, entity A has a property named ID and I am able to pass ID of A from jqGrid to the controller action; in that case, how could I use the ID to retrieve the collection of B belonging to that particular ID.
I am really new to Entity Framework and MVC, so any suggestion is really helpful. Please don’t mind if the question is so dumb.
If I remeber correctly, supposing you can also access A from B you would have something like this:
List<B> bs = YourDBContext.Bs.Where(b => b.A.ID == someID).ToList();