March 2008 - Posts
The P&P group recently published a set of WCF security related guidance. You'll find on this CodePlex site a series of articles and videos.
http://www.codeplex.com/WCFSecurity
In a previous post, I was explaining how surprised I was when I discovered that you lose LINQ to SQL change tracking features when working in a multi layered application or when you expose your business logic thru a service layer. Thanks to everyone (especially Barry Gervin, Rocky Lhotka, Julie Lerman and Rick Strahl) who pointed me to articles, blog posts and code samples, I was able to make sense of all of this.
Let’s take a look back at my rant and see how I can address each of these points. BTW, this is by no means the only way to achieve the goal of using LINQ to SQL in a multi layered application. It’s just simple and easy. Feel free to comment and share your findings and thoughts.
1-The presentation layer must reference the DAL directly because this is where the data mapping classes are located. Yuck!
Referencing the DAL objects from the presentation layer is bad because you’re creating a strong bond between these layers that are supposed to be decoupled. The rule states that the presentation layer must not be aware of the data access layer. What you really need to do is create a transport object layer that will be referenced by the BAL and the DAL. These objects are just plain POCOs (Plain Old CLR Objects) that will cross all the layers.
public class Customer
{
public string CustomerID { get; set; }
public string CompanyName { get; set; }
public string ContactName { get; set; }
public string City { get; set; }
}
In your LINQ query, just map the data directly back to your POCO. In this example, the data is mapped back to the Customer POCO.
public static List<TransportObjects.Northwind.Customer> SelectAllCustomers()
{
using (LINQ.NorthwindDataClassesDataContext ctx = new LINQ.NorthwindDataClassesDataContext())
{
var q = from c in ctx.Customers
select new TransportObjects.Northwind.Customer {CustomerID = c.CustomerID, ContactName = c.ContactName, City = c.City, CompanyName = c.CompanyName };
return q.ToList< TransportObjects.Northwind.Customer>();
}
}
2-By returning POCOs to the presentation layer instead you lose all the change tracking stuff provided by LINQ to SQL. Yuck!
One of the LINQ to SQL benefits is change tracking. Beside the actual data that is mapped to the objects, LINQ to SQL keeps a copy of that data so when you call the SubmitChanges method of the DataContext object, LINQ to SQL can figure out the objects that changed and can apply these changes (CRUD) back to the database. And yes, by having a transport objet, you are losing the change tracking benefit but it’s not the end of the world.
3-Exposing the BAL layer as a set of WCF services you lose the change tracking stuff. Yuck!
Change tracking IS state and state is bad in service oriented apps because by definition, they are supposed to be stateless. OK so how I’m supposed to return my POCOs back to the presentation layer using a WCF service layer? Simple, use the [DataContract] and [DataMember] attributes in your POCOs. Now they can cross the WCF service layer.
[DataContract]
public class Customer
{
[DataMember]
public string CustomerID { get; set; }
[DataMember]
public string CompanyName { get; set; }
[DataMember]
public string ContactName { get; set; }
[DataMember]
public string City { get; set; }
}
4-And what if I want to data bind my grid? Using the designer, I need to point to the DataClasses sitting in the DAL. Yuck!
No need to reference the LINQ classes to generate the correct bindings. After adding a service reference in your presentation layer, connect the BindingSource object to the WCF proxy classes then when you receive an array of POCOs from the WCF service layer, you only need to bind it to your grid.
5-OK, I'll lose the change tracking stuff. Now I'll have to reload each record before saving it? Yuck!
Yep, that’s one way to do it but you can apply business rules while doing that. You can of course do all of this in store procs.
That’s it! Not bad at all, right? Sure you lose the change tracking feature but you get the benefit of using LINQ to SQL in your DAL.
Drawbacks?
One drawback is when you have complex POCOs like the Order and OrderDetail ones with the Order object having a property of type OrderDetail. I haven’t found a way to return the Order object correctly stuffed with the OrderDetail data directly from the LINQ query. What I do is return an anonymous type then loop to build my POCOs, the drawback being that two object creation phases are needed: one for the anonymous types and one for the POCOs. I wouldn’t return thousands of records this way! I would simply use a store proc or plain old ADO.NET to retrieve the data, and then build the POCOs. If somebody has a clever way to do this, please post a comment!
[DataContract]
public class Order
{
[DataMember]
public int OrderID { get; set; }
[DataMember]
public string CustomerID { get; set; }
[DataMember]
public DateTime? OrderDate { get; set; }
[DataMember]
public DateTime? ShippedDate { get; set; }
[DataMember]
public string ShipCity { get; set; }
[DataMember]
public OrderDetail[] Detail { get; set; }
}
[DataContract]
public class OrderDetail
{
[DataMember]
public int OrderID { get; set; }
[DataMember]
public int ProductID { get; set; }
[DataMember]
public decimal UnitPrice { get; set; }
[DataMember]
public int Quantity { get; set; }
}
public static TransportObjects.Northwind.Order[] SelectCustomerOrders(string id)
{
using (LINQ.NorthwindDataClassesDataContext ctx = new LINQ.NorthwindDataClassesDataContext())
{
List< TransportObjects.Northwind.Order> ordersList = new List<TransportObjects.Northwind.Order>();
var q = from o in ctx.Orders
where o.CustomerID == id
select new { Detail = o.Order_Details, CustomerID = o.CustomerID, OrderDate = o.OrderDate, OrderID = o.OrderID, ShippedDate = o.ShippedDate, ShipCity = o.ShipCity };
foreach (var order in q)
{
TransportObjects.Northwind.Order tempOrder = new TransportObjects.Northwind.Order();
tempOrder.CustomerID = order.CustomerID;
tempOrder.OrderDate = order.OrderDate;
List<TransportObjects.Northwind.OrderDetail> ordersDetailList = new List< TransportObjects.Northwind.OrderDetail>();
foreach (var orderDetail in order.Detail)
{
TransportObjects.Northwind.OrderDetail tempOrderDetail = new TransportObjects.Northwind.OrderDetail();
tempOrderDetail.ProductID = orderDetail.ProductID;
ordersDetailList.Add(tempOrderDetail);
}
tempOrder.Detail = ordersDetailList.ToArray<TransportObjects.Northwind.OrderDetail>();
ordersList.Add(tempOrder);
}
return ordersList.ToArray<TransportObjects.Northwind.Order>();
}
}
Hope this helps!
When coding apps that use LINQ to SQL, it is very important to check the SQL code generated to make sure that your queries are optimals. To do this in a Console app, you simply use this code to output the query to the Console window:
ctx.Log = Console.Out;
That's nice but what if your code is in a class library project? Wouldn't it be nice to output the query to the Output window? Kris Vandermotten has created a small utility class to do just that. Check it out here:
http://www.u2u.info/Blogs/Kris/Lists/Posts/Post.aspx?ID=11
Nice work!

Eric De Carufel: Volta et le futur de la plateforme .NET
Nous discutons avec Eric De Carufel de la technologie Volta et de son impact sur la plateforme .NET. Volta est une des technologies développées par Microsoft Research dans le cadre du projet Tesla.
|
Eric De Carufel est conseiller chez CGI à Montreal. Il se spécialise dans le développement d’applications à l’aide de la plate-forme Microsoft .NET. Il possède plus dix années d’expérience en conception d'application d'entreprise dans les domaines du transport, de l’alimentation, de l'assurance et de l’ingénierie. Eric est membre du Groupe d'usagers Visual Studio .NET de Montreal et il est un collaborateur de Universal Thread Magazine. Eric est certifié développeur d’applications Microsoft (Microsoft Certified Application Developper – MCAD).
|
Télécharger l'émission
Si vous désirez un accès direct au fichier audio en format MP3 ou Windows Media (WMA), nous vous invitons à télécharger le fichier en utilisant un des boutons ci-dessous.
Si vous désirez utiliser le feed RSS pour télécharger l'émission, nous vous invitons à vous abonnez en utilisant le bouton ci-dessous.
Si vous désirez utiliser le répertoire iTunes Podcast pour télécharger l'émission, nous vous encourageons à vous abonnez en utilisant le bouton ci-dessous.
Last year, I bought a Dell Vostro 1700 with an Nvidia GeForce 8600M GT 2560MB graphic card with a respectable rating of 4.5 for Aero and 5.1 for gaming.


Of course, one of the first thing I did was to download the latest drivers from the Nvidia Website. To my surprise, Setup refused to install the drivers. After a little digging, I found that these drivers, altought good for all Nvidia graphic cards (desktop + mobile), don't install on laptops. Looks like Nvidia leaves that to the laptop manufacturers.
Looks like I was behind using ForceWare 156.69...

...so I went looking for upates on Dell's Website and I only found this:

Funny, Dell's latest drivers are dated June 2007 and version 101.43. Hummm, not good but I decided to give them a try anyway. Well, after the install, the Nvidia control panel reported that I was using ForceWare 101.43. Doh!

Worse, the Vista Aero rating went down from 4.5 to 4.4!

Since that was stepping back, I did a little research and found the LaptopVideo2Go Website. It's run by a bunch of enthousiasts that modify the INF file coming with the Nvidia setup so that the drivers are installable on laptops. Interesting!
WARNING: This might void your warranty, cripple your laptop forever, bring deadly plagues to the earth, render your dog blind, get your hair on fire, etc. Don't do this unless you backup your laptop, send flowers to your mother, give to United Way and learn to dance the salsa. You've been warned!
So I downloaded the latest drivers from the LaptopVideo2Go Website along with the modified INF file and I installed them. After the installation, the Nvidia control panel reported that I had ForceWare 169.09. Cool!

Now what about that Vista rating? Aero went back up to 4.5 and the gaming one went from 5.1 to 5.2. Yeah!

While doing a little browsing, I found a product that let you program with PHP inside Visual Studio 2005 & 2008. They even have a standalone version for those who don't have Visual Studio installed. The price is dirt cheap: $99. The only strange thing is that there is absolutely no info at all about the company on their Website. Strange is you ask me.
www.jcxsoftware.com

Interesting article in Wired this month by Leander Kahney called How Apple Got Everything Right By Doing Everything Wrong.
I keep telling people that the Microsoft that we have in 2008 is not the same Microsoft we had in the 80s-90s and I keep telling people that altought Apple puts out great and fantastic products, it is the new (old) Microsoft. The Wired article explains the whole thing a lot better than me.

After looking at Business Objects' Webpage about Crystal Reports 2008 for Visual Studio, you may conclude that the version included in Visual Studio 2008 is a "light" version of CR 2008.
http://www.businessobjects.com/product/catalog/crystalreports_visualstudio/
Well, not exactly. Here are the CR 2008 Basic DLLs. Note the version? Yep, that's 10.x

Here are the CR 2008 Full version DLLs. Note the version? Yep, that's 12!

So CR 2008 Basic, the version bundled with Visual Studio 2008, is not a scaled down or a light version of CR 2008. A quick call to Business Objects confirmed this. They said that it was version 10 along with some version 11 enhancements. IMHO, this will create a lot of confusion. They should have used a different name.
Now that Crystal Reports 2008 SP0 provide support for Visual Studio 2008, I installed it. Here's a screenshot of the setup process. Note that they kept the same product name as the one used in Visual Studio.

I was told (but did not test) that if you already installed CR 2008 Basic as part of the Visual Studio 2008 installation and you install Crystal Reports 2008, the Setup will upgrade your files from 10.x to version 12. There's no side by side installation possible.
Since it was impossible to move reports files from CR 2008 Basic to pre CR 2008 SP0, I wanted to test if they fixed that with SP0. Yep, it now works.


Laurent Duveau: Les nouveautés de la conférence MIX 2008
Nous discutons avec Laurent Duveau des nouveautés annoncées dans le cadre de la conférence MIX 2008 à laquelle Laurent a assisté. MIX est une conférence tenue annuellement pour les développeurs et les designers Web qui présente les dernières nouveautés produites par Microsoft pour la programmation Internet.
|
Laurent Duveau est un consultant et formateur pour la firme RunAtServer Consulting. Il se spécialise dans un domaine qu'il adore: les applications web avec ASP.NET, AJAX, Silverlight et la gamme Microsoft Expression. Laurent est certifié MCSD.NET, MCTS, MCPD et MCT. Il participe fréquemment aux activités de la communauté des développeurs .NET et du Groupe usager Visual Studio de Montréal. Il est également l'auteur d'articles techniques pour TechHeadBrothers et asp.net et contribue activement aux forums asp.net. Pour la seconde année consécutive, il a obtenu de Microsoft le titre de MVP ASP.NET.
|
Télécharger l'émission
Si vous désirez un accès direct au fichier audio en format MP3 ou Windows Media (WMA), nous vous invitons à télécharger le fichier en utilisant un des boutons ci-dessous.
Si vous désirez utiliser le feed RSS pour télécharger l'émission, nous vous invitons à vous abonnez en utilisant le bouton ci-dessous.
Si vous désirez utiliser le répertoire iTunes Podcast pour télécharger l'émission, nous vous encourageons à vous abonnez en utilisant le bouton ci-dessous.
Doing a little search on some of the new IE8 features, I found this page listing a series of IE8 whitepapers:
http://code.msdn.microsoft.com/ie8whitepapers
Amongst other things, you'll find documents on Activities, WebSlices and the Developer Tools.


Interesting enough, eBay supports Activities and WebSlices right now:
http://ie8.ebay.com/


More Posts
Next page »