Tuesday 15 July 2014

vb.net - How do I retrieve table data when it is a 'level down' in the class definition? -


VS2013, VB, EF, LINQ

Though maybe I can design a better model, it What I am is: The partial public class ApplicationDbContext public property ChannelItems DbSet (ChannelItem's) public property UserPosts DbSet (UserPost) as the end class folk class ChannelItem public property ChannelItemID integer New UserPost public property comments as public property anchor new list (UserPost) Public Property SpecialPermissionReq Boolean End Class Orbit UserPost Public Property as the UserPostID Integer ... Public Property HasBeenReadBy new list (HasBeenReadBy's) End Class Orbit Public Class HasBeenReadBy public property HasBeenReadByid integer as as as public Property name such as string and class

I need to use 'Include' in my questions with a little The Oshis like:

  viewmodel. CHannelItem = db.ChannelItems.Include ("Anchor"). Include E ("Comment"). Where (Function (x) x.ChannelItemID = ChannelItemID). FirstOrDefault ()  

I say conflict because I thought your project should be configured in a way that anchor and comments Automatically load, but I can not seem to figure that out. This is not my question, but there is only one way of saying that why I am so obliged in the 'Include' statement. This is the only way that I am currently able to ensure that all the data is retrieved during the query . Now, on my question.

Within my existing project configuration, I now need to include HasBeenReadBy data in UserPost. I want to retrieve that data when I want to find ChannelItems in a question, but I can not include HasBeenReadBy as follows:. Include

  dim allAnchorsInType = db.ChannelItems.Include ("Anchor") ("Comment"). Include ("HasBeenReadBy"). Where (Function (x) x.Anchor.Type = ChannelType) .toList ()  

Because HasBeenReadBy is not part of ChannelItems.

How do I include "HasBeenReadBy", or is it even possible? Although perhaps obvious, HasBeenReadBy data for anchor property, as well as comments in the Comments property HasBeenReadBy data is in each comment.

Or is my classroom design just plain naive?

After

In C # we use something like the following to select multilevel objects

  db.ChannelItems .clude (I => i.Anchor). (I = & gt; i.Comments.Select (c = & gt; c.HasBeenReadBy))  

Hope you can convert it to related VB code.


No comments:

Post a Comment