我正在与Linq奋斗到Entites。我是EF5和Linq的新手。我在VB.NET编程。我一直在使用表格适配器将DataSets作为DAL返回到BLL,然后我链接到ObjectDataSource。现在我从VS2005 ASP.NET 2.0升级到VS2012到ASO,.NET 4.0使用EF5,我已经设置了EF5作为DAL,我正在尝试重写BAL以使用Linq to Entities转到ObjectDataSource。我可以使用带有外键的Navigation I设置对多个表执行一些复杂的查询,但我不明白如何使用返回类型来处理需要DataSet的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 =来自DAL中的ct.Contents选择ct
为什么这在下面工作?为什么我必须使用include方法填充此类以使用1对多的2个表将其放入ObjectDataSource?
<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