我想获取在其个人资料中拥有博客ID的用户的用户名。如何从列表中的另一个实体获取一个实体
此代码返回所有的博客,并把它放在一个列表:
Dim blogs = db.Blogs.Include(Function(b) b.Company)
Return View(blogs.ToList())
我想包括到该博客列表所属的用户名。该数据保存在配置文件实体中(在名为“BlogId”的字段中)。
这是轮廓实体:
Imports System.Data.Entity
Imports System.ComponentModel.DataAnnotations
Public Class UserProfile
Public Property UserProfileId() As Integer
Public Property UserId() As Guid
Public Property CompanyId() As Integer
Public Property BlogId() As Integer
Public Property IsCompanyOwner As Boolean
Public Property IsBlogOwner As Boolean
End Class
Public Class UserProfileDbContext
Inherits DbContext
Public Property UserProfiles As DbSet(Of UserProfile)
End Class
我怎样才能获得用户名进入ToList(),以显示它在我的看法?
谢谢。
我在UserProfile对象的任何地方都看不到用户名。您是否在公司对象中投射到结果中? – JustinMichaels 2012-08-02 19:59:39
UserId是Users实体的外键。博客对象有一个名为“公司”的字段,但这不相关。 – user1477388 2012-08-02 20:03:06
你能不能在代码中发布你的用户对象? – JustinMichaels 2012-08-02 20:08:43