0

我有一个名为 blog 的对象和一个名为 article 的对象。一个博客里面有很多文章。我选择这样的博客:

Dim blogs = db.Blogs.Where(Function(b) b.CompanyId = companyId)

如何获取所选博客中的所有文章?

我想在所选博客的列表中显示文章:

Dim articles = ' How do I get all the articles inside of the blogs found?
Return View(articles.ToList())

我的博客实体如下:

Imports System.Data.Entity
Imports System.ComponentModel.DataAnnotations

Public Class Blog

    Public Property BlogId() As Integer
    Public Property CompanyId() As Integer
    Public Property Name() As String
    Public Property Description() As String
    Public Property DateCreated As Date

    Public Overridable Property Articles() As ICollection(Of Article)

    Public Overridable Property Company() As Company

End Class

Public Class BlogDbContext

    Inherits DbContext
    Public Property Blogs As DbSet(Of Blog)
    Public Property Companies As DbSet(Of Company)
End Class
4

1 回答 1

2
Dim articles = blogs.SelectMany(Function(b) b.Articles)
于 2012-08-02T15:08:43.350 回答