p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=560)
-   -   A ringing Endorsement for Wrox! Code from one of your competitor's books (http://p2p.wrox.com/showthread.php?t=86987)

vbboyd March 15th, 2012 06:39 PM

A ringing Endorsement for Wrox! Code from one of your competitor's books
 
I thought that you might find this interesting but one of your competitors that writes books about .NET had the following code in their book.
Code:

using System;
using System.Collections.Generic;
using System.Linq;
//using System.Web;
//using System.Web.UI;
//using System.Web.UI.WebControls;
using System.Text;

public partial class LINQDefault2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AdventureWorksDataContext dataContext = new AdventureWorksDataContext();
        var employees = from emp in dataContext.Employees
                        where e.Gender == 'F'
                        select emp;
        foreach(var employee in employees)
            Response.Write(employee.EmployeeID + "<br />");
    }
}

It took me a little while (about five minutes) but I figured out why this code was giving me compile errors. I fixed this problem This is bad. See if you want the challenge to fix this code.
There is one thing for certain, these people that wrote this book won't be stealing or taking any money away from you or Wrox anytime soon. Wrox books are the best there is out there in the market, and I give them a very ringing endorsement for their products. My question then becomes how responsive is Wrox to the errata that is submitted by the users of their books?
But my other question is if I wanted to write the output of the employeeId number in the code up above to a Gridview or a Listbox what do you think is the quickest and easiest approach to take?

Thank you once again!

Imar March 15th, 2012 06:50 PM

Quote:

See if you want the challenge to fix this code.

e.Gender should be emp.Gender

Quote:

My question then becomes how responsive is Wrox to the errata that is submitted by the users of their books?

In general: pretty good once you get past the errata form that asks a million questions, including your pet name and your **************** size ;-) Kidding aside, the process from Wrox to the author seems pretty quick, but then it depends on the author how long it takes for a reply. For my own books, I've looked at every errata item I've been sent and either confirmed the issue (which then got posted on the Wrox site), or explained why the submitted issue wasn't wrong or incorrect.

Quote:

But my other question is if I wanted to write the output of the employeeId number in the code up above to a Gridview or a Listbox what do you think is the quickest and easiest approach to take?

Assign a Data Source and call DataBind:

Code:


myGridView.DataSource = employees;
myGridView.DataBind();

This provides the entire Employee object to the grid, giving you access to all of its other properties. If you only need the ID, you could modify the LINQ query to select an anonymous object with only the employee ID.

Hope this helps,

Imar

Imar March 15th, 2012 06:52 PM

Haha, I love spam detection. I realize **** size can be anything ;-) In my case, I talked about footwear.... ;-)

Imar

vbboyd March 15th, 2012 07:25 PM

My real question is...
 
I am sorry and I guess I should have been more specific. What I was really wondering is it possible to filter the result set that you get back from a data set from LINQ so that say for instance you can load a list box with only the employees that are from Arizona and then filter another group of employees into a different list box that are from Wyoming? Could that be done in the where clause or just exactly is the best way to do this in code so that I can take two different filters one for the employees in Arizona and one for the employees in Wyoming and put their first and last names in separate drop down listboxes for each state?

Thanks once again!

Imar March 16th, 2012 05:28 AM

Quote:

What I was really wondering is it possible to filter the result set that you get back from a data set from LINQ
Sure....

Code:


AdventureWorksDataContext dataContext = new AdventureWorksDataContext();
var employees = from emp in dataContext.Employees
                        where e.Gender == 'F'
                        select emp;
 
var fromArizona = from emp in employees
                        where e.State == "Arizona"
                          select emp;
 
// Or use:
var fromArizona = employees.Where(e => e.State == "Arizona");
 
var fromWyoming  = from emp in employees
                              where e.State == "Wyoming"
                              select emp;
 
// Or use:
var fromWyoming = employees.Where(e => e.State == "Wyoming");

All of this assumes that the Employee has a State property... Since it queries the local query employees, these queries return Female employees only.

Imar


All times are GMT -4. The time now is 03:31 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.