使用EF5 link to Entities作为DAL to BLL to ObjectDataSource



我正在努力与Linq到实体。我是EF5和Linq的新手。我在VB.NET编程。我一直在使用表适配器,它将数据集作为DAL返回到一个BLL,然后链接到ObjectDataSource。现在我从VS2005 ASP升级到VS2012。. NET 2.0到ASO。. NET 4.0使用EF5,我已经将EF5设置为DAL,我正试图重写BAL以使用实体链接到ObjectDataSource。我可以做一些复杂的查询多个表使用导航我设置外键,但我不明白如何获得返回类型与ObjectDataSource工作,它期望一个数据集。

ContentQ = From ct In DAL.Contents, cd In ct.ContentDuplicateTypes, ce In ct.ContentEditors _
           Where ct.ContentId = Contentid And cd.ShowOnWeb = ShowOnWeb And cd.Hide = Hide And ce.UserId = UserId And ct.websiteId = websiteid Select ct, cd, ce

用于返回单个表ContentQ= From ct in DAL。内容选择ct

为什么下面会这样?为什么我必须填充这个类,以便使用include方法将其放入ObjectDataSource中,并使用1对多的2个表?

<System.ComponentModel.DataObjectMethodAttribute(ComponentModel.DataObjectMethodType.Select, True)> _
Public Function GetContentFiles() As ContentData
    Dim objContentData As New ContentData
    Using _SBEF As New SBEF5
        Dim objContentDuplicateType = From d In _SBEF.ContentDuplicateTypes.Include("Content") Select d
        For Each objQuery In objContentDuplicateType.ToList
            With objContentData
                'Content
                .Description = objQuery.Content.Description
                .FileName = objQuery.Content.FileName
                .Draft_Path = objQuery.Content.Draft_Path
                .Live_Path = objQuery.Content.Live_Path
                .HeaderTitle = objQuery.Content.HeaderTitle
                'ContentDuplicateType
                .ContentId = objQuery.ContentId
                .DisplayHeader = objQuery.DisplayHeader
                .OrderNumber = objQuery.OrderNumber
                .ShowOnWeb = objQuery.ShowOnWeb
                .Hide = objQuery.Hide
                .DateCreated = objQuery.DateCreated
                .ContentTypeID = objQuery.ContentTypeId
            End With
        Next
        GetContentFiles = objContentData
    End Using
End Function

为什么不使用EntityDataSource?

最新更新