M
Michael Starberg
Hi folks.
First up, sorry for sporting html, but I want the code to be nice below.
I typically educate/demo LINQ/.NET 3.5 and C# 3.0 to all who wants to know. At work that is for our coders, and for our customers; well.. they are curious... and pays for it.
My style is to sit at my laptop, connected to a projector, and let the curious watch me as I talk/explain and type away. What I typically end is what you can see below.
As for the bright dudes here; - What could I do better? Or Different? OrElse?
Any comments are appreciated. Constructive critque are welcome. Heck, even flames and insults are welcome.
My question is; - How would you change the demo-code below?
Happy Coding
-.Michael Starberg
-------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleDemo
{
#region Program
class Program
{
static void Main(string[] args)
{
(new Demo()).DoStuff();
Console.WriteLine();
Console.WriteLine("Done...");
Console.ReadLine();
}
}
#endregion
public class Demo
{
public void DoStuff()
{
var db = new NorthwndDataContext();
db.DeferredLoadingEnabled = false;
db.ObjectTrackingEnabled = false;
var lo = new DataLoadOptions();
lo.LoadWith<Customer>(c => c.Orders);
lo.LoadWith<Order>(o => o.Order_Details);
lo.LoadWith<Order_Detail>(od => od.Product);
lo.AssociateWith<Customer>(c =>
from o in c.Orders
where o.OrderDate.Value.Year > 1996
select o
);
db.LoadOptions = lo;
var query =
from c in db.Customers
where ((c.City != null) && (c.City == "London" || c.City == "Bräcke"))
select c;
//db.Log = Console.Out;
var customers = query.ToList();
foreach (var c in customers)
{
Console.WriteLine(c.CompanyName);
Console.WriteLine("---------------------------------------------------");
Console.WriteLine("---------------------------------------------------");
foreach (var o in c.Orders)
{
Console.WriteLine(
"{0} [{1}] ${2} total",
o.OrderDate.Value.ToShortDateString(),
o.Order_Details.Count(),
Convert.ToInt32(o.Order_Details.Sum(od => (od.Quantity * od.UnitPrice)))
);
foreach (var od in o.Order_Details)
{
Console.WriteLine(" - {0} [{1}]", od.Product.ProductName, od.Quantity);
}
Console.WriteLine("----");
}
Console.WriteLine();
}
}
}
}
// Thanks for reading this far =)
First up, sorry for sporting html, but I want the code to be nice below.
I typically educate/demo LINQ/.NET 3.5 and C# 3.0 to all who wants to know. At work that is for our coders, and for our customers; well.. they are curious... and pays for it.
My style is to sit at my laptop, connected to a projector, and let the curious watch me as I talk/explain and type away. What I typically end is what you can see below.
As for the bright dudes here; - What could I do better? Or Different? OrElse?
Any comments are appreciated. Constructive critque are welcome. Heck, even flames and insults are welcome.
My question is; - How would you change the demo-code below?
Happy Coding
-.Michael Starberg
-------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleDemo
{
#region Program
class Program
{
static void Main(string[] args)
{
(new Demo()).DoStuff();
Console.WriteLine();
Console.WriteLine("Done...");
Console.ReadLine();
}
}
#endregion
public class Demo
{
public void DoStuff()
{
var db = new NorthwndDataContext();
db.DeferredLoadingEnabled = false;
db.ObjectTrackingEnabled = false;
var lo = new DataLoadOptions();
lo.LoadWith<Customer>(c => c.Orders);
lo.LoadWith<Order>(o => o.Order_Details);
lo.LoadWith<Order_Detail>(od => od.Product);
lo.AssociateWith<Customer>(c =>
from o in c.Orders
where o.OrderDate.Value.Year > 1996
select o
);
db.LoadOptions = lo;
var query =
from c in db.Customers
where ((c.City != null) && (c.City == "London" || c.City == "Bräcke"))
select c;
//db.Log = Console.Out;
var customers = query.ToList();
foreach (var c in customers)
{
Console.WriteLine(c.CompanyName);
Console.WriteLine("---------------------------------------------------");
Console.WriteLine("---------------------------------------------------");
foreach (var o in c.Orders)
{
Console.WriteLine(
"{0} [{1}] ${2} total",
o.OrderDate.Value.ToShortDateString(),
o.Order_Details.Count(),
Convert.ToInt32(o.Order_Details.Sum(od => (od.Quantity * od.UnitPrice)))
);
foreach (var od in o.Order_Details)
{
Console.WriteLine(" - {0} [{1}]", od.Product.ProductName, od.Quantity);
}
Console.WriteLine("----");
}
Console.WriteLine();
}
}
}
}
// Thanks for reading this far =)