Wednesday, April 02, 2008

In my previous post about using LINQ to SQL in multi layered apps, I mentioned that this query was not optimal because I would need to build the POCOs from the objects returned by LINQ.  This would mean that objects would be created twice. 

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 };

Not ideal so I asked if anyone had an idea on how to do that.  Stefan Sedich suggested this query:

var q = from o in ctx.Orders
where o.CustomerID == id
select new TransportObjects.Northwind.Order {

Detail = o.Order_Details.Select(item => new  TransportObjects.Northwind.OrderDetail {
ProductID = item.ProductID 
}).ToArray(),

CustomerID = o.CustomerID,
OrderDate = o.OrderDate,
OrderID = o.OrderID,
ShippedDate = o.ShippedDate,
ShipCity = o.ShipCity};

Cool!  The query returns the Order complex object with the Detail property filled from orders Details.

Thanks a lot Stefan!

 

Wednesday, April 02, 2008 7:04:54 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
Tuesday, April 01, 2008

Enterprise Library 4.0 March 2008 CTP was released yesterday.

http://www.codeplex.com/entlib

Tuesday, April 01, 2008 8:03:08 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

My good friend Mario Cardinal just got one article published on MSDN.  It's called The Hidden Roles of Software Architects.  Check it out:
http://msdn2.microsoft.com/en-us/library/cc431351.aspx

Tuesday, April 01, 2008 7:52:47 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

Team Suite Vnext will be FREE (but ad supported)

At Mix08 in Las Vegas, I had the chance (!) to be invited to a special meeting.  The invite was for only 12 people and it was to demonstrate a revolutionary new Visual Studio feature.  We gathered with Scott Guthrie in a private room at the Aquaknox restaurant at the Venetian hotel where we were treated with exquisite seafood that would have a bad taste later on.

So what is that revolutionary new Visual Studio feature?  Well, Microsoft plans to offer the next Visual Studio Version for free.  Yeah, Visual Studio Express is already free you might say but I’m talking about the Team Suite here!  Yep, Microsoft plans to offer the $10K product for free!!!  So watch the catch?  Isn’t that some good news?  Well, Microsoft has some large teams dedicated to the development tools and they need to generate revenues to pay for those salaries so the Visual Studio VNext will be free but add supported.  You might say that’s it’s a good deal because you get a $10K product for free by watching a few non obstructive ads well here the catch: the ads are obstructive.  How obstructive?  Check this out.
First of all, the advert system code name is called Barracuda.  It is already included in the August CTP of Visual Studio Team Suite code name Rosario.  You may have downloaded that version and found nothing special; this is because it is not activated by default.  To activate it, Microsoft has created something clever: you need to input a special set of buttons from an Xbox 360 game controller!

So you need to connect an Xbox 360 controller to an USB port (the wireless one will also work) on the machine running Rosario and you need to input the button sequence in this precise order:
At the same time: press the Left trigger + Right trigger + Left thumbstick UP + Right thumbstick DOWN
While the above are pressed, press the D-pad in this order: Up, Left, Up, Down, Up, Right
If you entered the correct sequence, the controller will vibrate and this dialog will pop-up inviting you to restart Visual Studio.

After restarting Visual Studio, create a class library project and take a look at the code.  Yep that’s an ad placed directly on top of your code and no way to turn it off!

Now shut down Visual Studio, unplug your network cable so you don’t have any Internet access and restart Visual Studio.  You’ll be prompted by this dialog:

Yes, an Internet connection will be required to use that free ad supported Visual Studio.  If you dismiss this dialog, Visual Studio just closes.  That’s it!  Impossible to use it on the train or at a client without being connected to their network.  How convenient!

Now the shocking part (yes there are more shocking news!): when the application is compiled and deployed, the add system doesn’t go away because it’s built in the .NET Framework 4.0. When your users will start your app, they will be presented with an ad!

Microsoft has not completed the Web start-up ad yet but the plan is to whenever a new session starts, the start-up ad will be presented in a DHTML window over your actual application in the browser.  Shocking?  Wait, there’s more!
The ad system is connected with ADO.NET so ads are inserted right into the data you’re displaying.  The plan is to have one ad being displayed at all time in grids. 

Oh BTW, your users will also have to be connected to the Internet or your app will simply not run!

I don’t know about you but that whole ad supported Visual Studio thing smells fishy.  I don’t like it at all and I’d rather pay for Visual Studio then get it for free and annoy my users.  Before posting this info, I contacted Scott Guthrie for voicing my concerns.  This is what he had to say:  April Fools!!!!

 

Tuesday, April 01, 2008 5:53:04 AM (Eastern Standard Time, UTC-05:00)  #    Comments [1]  | 
Monday, March 31, 2008

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

Monday, March 31, 2008 9:00:11 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

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!

Monday, March 31, 2008 8:45:21 PM (Eastern Standard Time, UTC-05:00)  #    Comments [1]  | 

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!

Monday, March 31, 2008 7:47:55 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
Sunday, March 30, 2008

Accueil

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.

Sunday, March 30, 2008 3:32:13 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
Sunday, March 23, 2008

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.

Dell_vostro_17001.jpg

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!

Sunday, March 23, 2008 9:15:15 AM (Eastern Standard Time, UTC-05:00)  #    Comments [1]  | 
Friday, March 21, 2008

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

VS.Php for Visual Studio 2008

Friday, March 21, 2008 4:08:11 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
Wednesday, March 19, 2008

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 me.

Wednesday, March 19, 2008 6:05:52 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
Monday, March 17, 2008

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.

Monday, March 17, 2008 12:04:18 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

Accueil

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.

Monday, March 17, 2008 5:47:26 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
Sunday, March 16, 2008

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/

eBay Search Activity

eBay Webslice

Sunday, March 16, 2008 6:20:28 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

[From Eric Moreau]

Ever wish you could test a LINQ query without pressing F5 in Visual Studio?  Book author Joseph Albahari who wrote C# 3.0 in a NutShell has released LINQPad, a free tool that let you do just that.  Coolness factor: 11!

Sunday, March 16, 2008 8:06:30 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

[From Eric Moreau]

PowerCommands is a set of cool and useful Visual Studio 2008 extensions.  Free + source code is included.

PowerCommands.jpg

http://www.visualstudiogallery.com/ExtensionDetails.aspx?ExtensionID=df3f0c30-3d37-4e06-9ef8-3bff3508be31

 

Sunday, March 16, 2008 7:44:53 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

At Mix08, I had the chance to record a quick interview with Qixing Zheng. Qixing is a UX advisor for Microsoft Canada.  If you're doing anything UX related and you're in Canada, make sure to bookmark the Canadian UX Connection blog.

Mix08-Qixing.mp3 (2.6 MB)

Sunday, March 16, 2008 7:30:54 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
Thursday, March 13, 2008

[Follow up from my previous post]

OK, more info....

A quick call to Business Objects lead to this:

  • CR 2008 Basic is NOT a scaled down version of CR 2008 "Full".  It is in fact version 10 + some features from version 11
  • There are NO versions (9,10,11,2008) of CR that are compatible with VS 2008
  • BO will release an update to CR 2008 that will make it compatible with VS 2008
  • It will be possible to load the reports created with the "Basic" version in the "Full" updated version.  I must say that the person at the end of the line was very vague about this. 

After that call, I did a little research and found that CR 2008 SP0 was released just a couple of days ago.  That version is now compatible with VS 2008.
http://technicalsupport.businessobjects.com/cs/forums/thread/19171.aspx
http://support.businessobjects.com/communityCS/TechnicalPapers/cr_2008_supported_platforms_windows_sp0.pdf.asp
http://support.businessobjects.com/downloads/service_packs/crystal_reports_en.asp

Thursday, March 13, 2008 1:56:18 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

I'd like to thank Rod Paddock for doing his Annual Canadian User Group World Tour again this year.  He spoke on Monday in Montreal, then Tuesday in Ottawa and finally Wednesday in Toronto.

The fun part was getting to Montreal.  Rod attended Mix08 in Las Vegas the week before and instead of flying home to Seattle then fly again to Montreal, he decided to fly from Vegas to Montreal. 

Rod'd original itinerary was to fly from:

  1. Las Vegas to Detroit
  2. Detroit to Montreal

Well, the North East was hit with a major snow storm so Rod final itinerary looked like this:

  1. Las Vegas to Detroit
  2. Detroit to New York
  3. Saying no to a 10 hours bus ride (+ 3 hours at customs) to Montreal
  4. New York to Detroit
  5. Detroit to Montreal

Thanks a lot Rod for really really wanting to do this tour!

BTW, Rod is a fantastic speaker and he is on the INETA's speakers bureau.  If you're an INETA user group, make sure to invite Rod at some point.

Thursday, March 13, 2008 11:57:33 AM (Eastern Standard Time, UTC-05:00)  #    Comments [2]  | 

Any Crystal Reports experts here?  Not sure if I get this right....

There are 2 versions of CR 2008: the one that is bundled with Visual Studio 2008 called "Basic" and the "Full" one that you buy from Business Objects.

  • CR 2008 Basic cannot load CR 2008 "Full" reports.
  • CR 2008 "Full" is not compatible with VS 2008 until Bussiness Objects release a SP/update in Q2 2008.
  • CR 2008 Basic reports can't migrate to CR 2008 "Full".

So I can't use CR 2008 "Full" right now in my VS 2008 projects and by using the Basic version, I will be cornered because I won't be able to upgrade my reports to the "Full" version.

That can't be right!

Crystal Reports Migration

Thursday, March 13, 2008 11:42:17 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  |