I am working with Entity Framework to retrive blog data from a database. I have a class "BlogPost" and a class "Author". One Author may have many blog posts, but the Author object itself does not contain a list of them. As far as the Author object is concerned, it is independent of all blog posts.
An instance of the Author class is included as a property in the BlogPost. Every author has an AuthorId. I would like to pull from my database a given blog and have the Author object filled with the pertinent data. I have managed to do this by including an AuthorId property in my BlogPost class, using the following code to map the object:
this.HasRequired(t => t.Author).WithMany().HasForeignKey(x => x.AuthorId);
What I would like to do, however, is to be able to do the same thing but without having to include the AuthorId property directly in the model. The reason being, is because as the Author object contains the coresponding ID already, I am repeating the same piece of information twice. I would like to do something along these lines:
this.Property(t => t.Author.Id).HasColumnName("id_user");
this.HasRequired<TwitterUser>(t => t.Author).WithMany().HasForeignKey(t => t.Author.Id);
So, is there any way do retrieve the Author sub-object without having to store the AuthorID redundantly in the BlogPost object alongside the Author object itself?