我使用LINQ努力的entites。我是EF5和Linq的新手。我在VB.NET中编程。我一直在使用将数据集作为DAL返回到BLL中的表适配器,然后将其链接到ObjectDataSource。现在我升级到VS2012从VS2005 ASP.NET 2.0 ASO,.NET 4.0使用EF5和我已经安装EF5为DAL和我想重写BAL使用LINQ到实体去到ObjectDataSource。我可以使用Navigation I设置外键对多个表执行一些复杂的查询,但我不明白如何让返回类型与需要DataSet的ObjectDataSource一起工作。使用EF5 LINQ到实体为DAL到BLL到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
对于DAL.Contents选择克拉返回单个表例如 ContentQ =从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
一目了然,而不是更多地了解你的应用程序,你可能需要到ObjectDataSource映射到返回的实体(或映射实体正在使用的ObjectDataSource控件的对象),而不是一个DataSet。我从来没有使用过一个DataSet的ObjectDataSource - 只用我写的自定义类。 – Tim 2013-03-24 03:44:08
现在让我来展开这个问题。看起来,在GridView中进行分页和排序的唯一方法是使用自定义分页和自定义排序,其中必须通过表格的sorttag和MaxCount。有趣的是来自表格适配器的数据集自动获取。我想知道Linq to Entity开销是否与DataSets相同? Hmmmmm – 2013-03-26 21:57:12