I have created POCO domain objects that map to the entities in the entity domain model. Everything was working fine until now when I have to work with the many-to-many relationship.
Let's say I have three tables.
- Blog
- BlogTag
- Tag
You can see that Blogs and Tags are many-to-many with a bridge table, BlogTag that contains a foreign key to both tables.
I also have corresponding domain models:
- Blogs
- BlogsTags
- Tags
Now, I select a list of blogs and I'm trying to access a particular tag from a blog.
myBlog.BlogsTags[0].Tag
BlogTags[0].TagForeignKey is filled in, but BlogTags[0].Tag is null !!
I also have LazyLoading turned on.
What could I be doing wrong?
Thanks.
Okay. Here's some source code.
my context class
public class MyContext : ObjectContext
{
public MyContext() : base(Utility.GetConnectionString(...), "containerName")
{
Blogs = CreateObjectSet<Blog>();
BlogsTags = CreateObjectSet<BlogTag>();
Tags = CreateObjectSet<Tags>();
base.ContextOptions.LazyLoadingEnabled = true;
}
public ObjectSet<Blog> Blogs { get; private set; }
public ObjectSet<BlogTag> BlogsTags { get; private set; }
public ObjectSet<Tags> Tags { get; private set; }
}
and my poco classes just have a list of related objects with the virtual keyword.