Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #51 (permalink)  
Old December 11th, 2013, 01:42 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default DynamicQuery Library

Thanks Imar, I was hoping you would comment on the use of Sortby. "Order by" in the query statement is what I originally tried to do - and it seemed overly complicated for my simple needs. I saw some examples that looked fairly simple but I couldn't get them to work - other examples required a fair amount of code and were all in C#. I also tried "Orderby" and it didn't work - as you say, it must have needed the dynamic library.

I think I recall somewhere in your book(s) mentioning Dynamic Queries but not intending to address them - is this correct or did I miss something?

If I should need to use a dynamic query, I assume I'd need to download a library but searching NuGet doesn't seem to show such a library. Is there a library that needs to be installed?
  #52 (permalink)  
Old December 11th, 2013, 03:35 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

If it sorts, it sorts ;-) SortBy is actually an extension method inside the WebControls and not part of LINQ. However, it's convenient as it supports string based ordering.

For string based ordering without a dependency on the WebControls assembly, you can use the DynamicQuery library, found here: http://www.nuget.org/packages/DynamicQuery/

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
daveharney (December 11th, 2013)
  #53 (permalink)  
Old December 11th, 2013, 10:13 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default Beating a Dead Horse

Hi Imar,

Although I'm pretty sure the Sortby thing will suffice for me, I thought I'd try the dynamic method. I installed the dynamicquery package and now I have dynamic.dll in my bin. I tried this little experiment (in a variety of flavors):

Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DynamicSort.aspx.vb" Inherits="DynamicSort" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" 
            AutoGenerateColumns="False"
           selectmethod="GridView1_GetData">
            <Columns>
                <asp:BoundField DataField="StudentName" HeaderText="StudentName" />
                <asp:BoundField DataField="CourseName" HeaderText="CourseName"  />
                <asp:BoundField DataField="CourseNo" HeaderText="CourseNo" ReadOnly="True"  />
                <asp:BoundField DataField="StudentId" HeaderText="StudentId" ReadOnly="True"  />
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>
Code:
Imports SchoolEntities
Imports System.Linq
Imports System.Linq.Dynamic
Partial Class DynamicSort
    Inherits System.Web.UI.Page

    Public Function GridView1_GetData() As IEnumerable
        Dim dbcontext As New SchoolEntities()
        Dim orderByString As String = "CourseName"
        '  Dim orderByString As String = "s." + "CourseName"  ' this doesn't work either

        ' Order By s.CourseName  ' this works for regular non-dynamic
        ' Order By ("orderByString") ' this does not work as an attempt at dynamic

        Dim mylist = From s In dbcontext.EnrollStudentCourses
                    Order By ("orderByString")
            Select New With {s.CourseName, s.CourseNo, s.StudentId, s.StudentName}
        Return mylist.ToList()
    End Function
End Class
If you see something obvious, please let me know (I don't think your book will cover dynamic - but this can of worms is open). This code looks a lot like the examples that are given for dynamic queries (however I've not seen one tied to a gridview), but obviously something is wrong because the gridview is not displayed in order by CoursName. Debugging shows that orderByString is substituted with "CourseName" but the actual SQL does not reflect this substitution. No dynamic action here!
  #54 (permalink)  
Old February 13th, 2014, 05:06 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default Web Site vs Web Application

Hi Imar,

At the beginning of your books you note: "You must use the Web Site Project model if you want to follow along with this book". At various times I wondered if this was the right choice as many examples found outside of this book, for solving problems not specifically covered by the book, use Web Applications and MVC. Several times I wandered into MVC and each time decided it was overkill for a relatively simple, non-team, non-enterprise type of web site. And, I really didn't want to spend the time to learn the MVC technology.

The latest issue arose with my decision to develop a mini version of my site using jQuery Mobile. This technology seemed pretty easy to learn and I felt I could reuse much of the code I developed by following your book. You kindly went beyond the scope of your book to suggest using MS Web Api to reuse my EF-linq code for DB access. This was a very good suggestion but I soon discovered that most of the Web Api examples floating around on the internet used MVC (and, of course C#). Eventually (but painfully), I found enough info to create a first version of my mobile app.

In the end, the code needed to employ the Web Api in a simple web site turned out to also be extremely simple. No Web Application or MVC needed - once again a Web Site Project works just fine.

This last experience confirms again that sticking with a Web Site Project is the right strategy for an web site like mine - I wish I could say the same for sticking with VB vs C #.

I assume the new book will continue with the Web Site Project approach?
  #55 (permalink)  
Old February 15th, 2014, 10:43 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Dave,

Quote:
I assume the new book will continue with the Web Site Project approach?
Yes. I just finished it this week and it should be out in March. It still used a Web Site Project and has examples on VB and C#.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!




Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP, Original PHP, Mysql and Apacher versions used in the book Sam321 BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 1 August 12th, 2012 07:07 AM
Different Versions of IE South Side Rob BOOK: CSS Instant Results 1 February 26th, 2009 06:05 PM
VS versions??? SKhna Javascript 1 February 4th, 2008 03:27 PM
Book Versions MER78 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 September 24th, 2004 02:56 PM
Java Versions? maayub J2EE 4 August 22nd, 2003 05:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.