0

I am struggling with Linq to Entites. I am new to EF5 and Linq. I am programming in VB.NET. I have been using Table Adapters that return DataSets as the DAL into a BLL that I then linked to ObjectDataSource. Now I upgraded to VS2012 from VS2005 ASP.NET 2.0 to ASO,.NET 4.0 to use EF5 and I have setup EF5 as the DAL and I am trying to rewrite the BAL to use the Linq to Entities to go to the ObjectDataSource. I can do some complex queries over multiple tables using the Navigation I setup with Foreign keys but I don't understand how to get the return type to work with the ObjectDataSource which expects a DataSet.

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

For returning a single table for example ContentQ= From ct in DAL.Contents select ct

Why does this work below? Why do I have to populate this class to get it into the ObjectDataSource with a 1-to-many of 2 tables using the include method?

<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
  • At a glance, and not knowing more about your application, you would probably need to map the ObjectDataSource to the entity being returned (or map the entity to the object being used by the ObjectDataSource), rather than a DataSet. I've never used an ObjectDataSource with a DataSet - only with custom classes I wrote. – Tim Mar 24 '13 at 03:44
  • Now let me expand the question. It appears that the only way to get Paging and Sorting in a GridView is to use Custom paging and Custom Sorting where one must pass in the sorttag and MaxCount of the table. Interesting where a DataSet from a Table adapter gets that automatically. I wonder if the Linq to Entity overhead is the same as DataSets? Hmmmmm – James Perkins Mar 26 '13 at 21:57

1 Answers1

1

Why are you not utilizing the EntityDataSource?

OneFineDay
  • 9,004
  • 3
  • 26
  • 37
  • The EntityDataSource is limited only on a single Table(Entity) and cannot work when quering multiple tables. It locks out Edit, Insert, and Delete. – James Perkins Mar 26 '13 at 21:54
  • I see how to get data from a single entity(table) what about a query that pulls from multiple tables using the navigation? Is the type Anomynious(sic) and do I set the function type to IQueryable only? – James Perkins Mar 26 '13 at 22:07
  • What if I create a view and make that an entity will the CRUD still work from the GridView? Bottom line I am trying to replace my DAL which was using Table Adapters with Entity Frame work Linq to Entities that then feeds a Business Layer class with properties, Select, Insert, Delete to be used with an ObjectDataSource. – James Perkins Mar 26 '13 at 22:08
  • Any examples of a Business class that uses a select statement for a single entity and a select statement that is querying over multiple entities using the navigation elements to then be consumed my the ObjectDataSource? – James Perkins Mar 26 '13 at 22:09
  • Can you give an example of what you mean by querying over multiple tables? You can more than one EDS. The navigation properties help to expose the related data. I typically use the IQueryable object, but think there are other options. – OneFineDay Mar 27 '13 at 00:30
  • My Example querying over 3 tables: ContentQ = From ct In _SBEF.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 = WEB.GlobalWebsiteID Select ct, cd, ce My main question would be what is my return type? Do I set the function type to IQueryable or IEnumerable? If I wrap it in a Using statement will it close before being processed? – James Perkins Mar 29 '13 at 07:20