2013-03-24 21 views
0

我使用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 
+0

一目了然,而不是更多地了解你的应用程序,你可能需要到ObjectDataSource映射到返回的实体(或映射实体正在使用的ObjectDataSource控件的对象),而不是一个DataSet。我从来没有使用过一个DataSet的ObjectDataSource - 只用我写的自定义类。 – Tim 2013-03-24 03:44:08

+0

现在让我来展开这个问题。看起来,在GridView中进行分页和排序的唯一方法是使用自定义分页和自定义排序,其中必须通过表格的sorttag和MaxCount。有趣的是来自表格适配器的数据集自动获取。我想知道Linq to Entity开销是否与DataSets相同? Hmmmmm – 2013-03-26 21:57:12

回答

1

你为什么不利用EntityDataSource

+0

该EntityDataSource只在一个单一的表(实体)的限制和quering多个表时不能工作。它锁定编辑,插入和删除。 – 2013-03-26 21:54:42

+0

我看到如何从单个实体(表)获取数据如何使用导航从多个表中提取查询?类型是否是异步(原文如此),并且仅将函数类型设置为IQueryable? – 2013-03-26 22:07:04

+0

如果我创建了一个视图并且使得一个实体能够从GridView继续工作,那该怎么办?我试图取代我DAL这是使用表适配器与实体框架的工作LINQ到实体是随后把与性业务层类底线,选择,插入,删除与一个ObjectDataSource使用。 – 2013-03-26 22:08:15