• Beth Massi - Sharing the goodness

    DevTeach 2010 Recap

    • 3 Comments

    DevTeach is finally winding down and my sessions are all done. It’s been a great conference, as always. I have been speaking at DevTeach since the second year and it’s always a great time chatting with Canadians about software development. This year I had the pleasure of kicking off the conference on Tuesday morning with the Keynote. I did a Lap around Visual Studio 2010 and I showed fun IDE features and extensibility, showed off a couple of my favorite language enhancements, new Entity Framework 4 & WCF Data Services, new WPF designer and data binding, and Silverlight and SharePoint 2010 tools. It was fun and I think people were pumped.

    Here’s some good links to check out for VS2010:

    Right after the Keynote I had a session that I’ve spoken about many times before (always a crowd pleaser) on VB10 / C#4 language features which are covered in these walkthroughs, articles and videos, on MSDN:

    I also did an off-the-cuff talk yesterday with Jon Aneja at lunch on using Open XML and XML Literals in VB to manipulate Office document formats.

    My last session was today on Building Office Productivity Solutions with Visual Studio 2010 and according to the evals it went well just like my language talk. We created an OBA for good old Northwind Traders, bringing them into the 21st century. ;-)  I showed the new features of VS2010 that makes Office development easier focusing on RAD data binding (including WPF) and designers, ribbon and the other available designers, as well as SharePoint 2010 tools around workflow and visual web parts.

    My main goal was to provide a real-world scenario and architecture but keep the demo code manageable and simple while also introducing folks to all the RAD designers available. This way you can take apart the sample easily and reuse just the pieces you need. Check out the code and all the articles here: http://code.msdn.microsoft.com/OBANorthwind and check out the VSTO Developer Center for more awesome resources: http://msdn.com/vsto

    Some of the new features that make Office development and deployment easier are covered in these walkthroughs:

    Here are some pictures from the conference which was held at a really nice Microsoft facility in Mississauga.

    IMG_2013 IMG_2024 IMG_2025 IMG_2006 IMG_2008 IMG_2009 IMG_2010 IMG_2011 IMG_2014 IMG_2015 IMG_2019 IMG_2023

    Now it’s time to get some dinner and good beer. ;-) Goodbye, Canada. Thanks for the awesome hospitality. See you next time!

  • Beth Massi - Sharing the goodness

    DevTeach Here I Come!

    • 4 Comments

    I’m heading up to Toronto this week for the DevTeach conference! I’ve spoken at DevTeach every time except for the very first one. This is a great Canadian conference that really brings a bunch of awesome speakers in our industry into a more intimate setting than say a TechEd. Check out all the sessions here. This year there’s a SharePoint track that I’m really excited about.

    I’m doing the keynote this time and I’m going to make an attempt at showing off some of the awesome new features in Visual Studio 2010. I’ve got some IDE tricks up my sleeve and I’ll walk through some language, parallel, data, WPF and SharePoint tools and features. I can’t hit everything because there’s so much packed into Visual Studio 2010 that it would take a full day to explore, but hopefully this gets people excited enough attend the rest of the sessions to learn more. My sessions tend to be pretty demo-heavy so look for less than 15 minutes of Keynote slides and the rest of the time I’ll be wowing the crowd (at least I hope) with real demos. I want to get the crowd PUMPED UP so if I have to put on my tap shoes so be it. ;-)

    I’m also doing a session on VB 10 & C# 4 new language features and a session on building on Office and SharePoint that should be a lot of fun.

    Hope to see you there!

  • Beth Massi - Sharing the goodness

    Office Development with Visual Studio Tutorial Series – Part 4

    • 1 Comments

    A couple months ago Robert Green, VSTO MVP, started a series of step-by-step tutorials on building on Office 2007. Part 4 is now published. Thanks Robert!

    In this fourth part of the series of tutorials on Office Business Applications, learn how to create an Excel 2007 solution using Visual Studio 2008 that generates reports from a database and allows you to take those reports offline. This tutorial shows you how to cache the set of data directly in the Excel workbook and also shows you how to easily print the data as a PDF. This step-by-step tutorial also includes full source code in Visual Basic & C#. Check out the tutorial on the VSTO Developer Center:

    Building an Office Business Application Part 4 – Generating Reports

    And if you missed the previous tutorials:

    These tutorials are pretty popular so if you’re just getting started with Office development in Visual Studio, this is a great place to start. Download all the code here: http://code.msdn.microsoft.com/ContosoAutoOBA

    Enjoy!

  • Beth Massi - Sharing the goodness

    Generic Co- and Contravariance in Visual Basic 2010

    • 2 Comments

    In this month’s issue of MSDN Magazine we’ve got an article on a new language/.NET 4 feature called Generic Co- and Contravariance by Binyam Kelile:

    MSDN Magazine: Generic Co- and Contravariance in Visual Basic 2010

    I have to admit if I think about this feature too hard my head starts spinning in circles faster than Linda Blair in the Exorcist. But in actuality it’s one of those features that “just works” and probably should have already been available in the CLR. The easiest way for me to think about it is that it enables true inheritance scenarios with generics.

    Consider this practical example. Say I have a class called Student that inherits from Person:

    Public Class Person
        Property Name As String
        Property Age As Integer
    End Class
    
    Public Class Student
        Inherits Person
    
        Public Property Score As Decimal
    End Class
    

    Now say I have a generic List(Of Student) that I want to pass to a method that accepts an IEnumerable(Of Person)):

    Sub Main()
        Dim students As New List(Of Student) From
            {New Student With {.Name = "Beth", .Age = 10, .Score = 90.5},
             New Student With {.Name = "Alan", .Age = 11, .Score = 100},
             New Student With {.Name = "Jenn", .Age = 12, .Score = 98.5}}
    
    
        PrintNames(students) 'This will not work in VS2008
    End Sub
    
    Sub PrintNames(ByVal list As IEnumerable(Of Person))
        For Each p In list
            Console.WriteLine(p.Name)
        Next
    End Sub

    Even though a List implements IEnumerable and a Student inherits from Person this will not work in Visual Studio 2008 because generic types behave invariantly in the CLR previous to version 4.0. This is now supported. In Visual Basic 10 (and C# 4) you now have the ability to declare covariant (widening) and contravariant (narrowing) generic types with the Out and In modifiers. So they changed the IEnumerable interface in the CLR 4.0 to designate a covariant generic type:

    Public Interface IEnumerable(Of Out T) ...

    So this means that the method call above will work now because a widening conversion is allowed. Contravariance is the exact opposite. With the In modifier on the generic type a narrowing conversion is allowed. Piece of cake, right?

    Check out the Generic Co- and Contravariance article for a deep dive into this feature and how to use it in your programs. Also check out Lucian’s post: Co- and contra-variance: how do I convert a List(Of Apple) into a List(Of Fruit)?

    Enjoy!

  • Beth Massi - Sharing the goodness

    Visual Basic Samples for a Variety of New Microsoft Technologies

    • 6 Comments

    Teams here at Microsoft have been cranking on a bunch of samples for the next releases of Visual Studio, .NET Framework, Office, SharePoint, Expression, WPF & Silverlight and I’ve been on the hunt to find some favorites and roll them up here. I haven’t played with all of these but depending on what you’re into you probably want to check these out.

    Visual Basic Samples
    These are a cumulative batch of over 100 samples, demonstrating features found in VS 2010, 2008, 2005 and earlier. You can explore new Visual Basic 10 (VS 2010) samples in the languages section.

    Samples for Parallel Programming with the .NET Framework 4
    This download includes both VB and C# samples for developers writing parallel and concurrent applications, including Parallel LINQ (PLINQ), the Task Parallel Library (TPL), new thread-safe collections, and a variety of new coordination and synchronization data structures.

    Office Development in Visual Studio 2010
    Visual Studio 2010 samples demonstrate Office development projects, tools, and techniques. Samples include Excel, Word and Outlook solutions.

    SharePoint Development in Visual Studio 2010
    Learn how to use the SharePoint development tools in Visual Studio 2010 to create SharePoint workflows, design and deploy visual web parts, event receivers, custom Business Data Catalog types, and list items in a SharePoint Web site.

    Windows Presentation Foundation (WPF) Documentation Samples
    This is a set of over 20 samples that complement the WPF documentation on MSDN.

    WPF & Silverlight Data Binding in Visual Studio 2010
    These samples demonstrate how to create a WPF & Silverlight data-based forms solutions using Visual Studio 2010.

    Silverlight Toolkit Samples
    The Silverlight Toolkit is a collection of Silverlight controls, components and utilities made available outside the normal Silverlight release cycle. This set of online samples include both VB and C#.

    Twitter Analyzer
    This sample shows how to interop from a Visual Basic WPF application with IronPython to search and filter twitter feeds as well as export the results to Excel.

    VB Samples for Expression Encoder 3
    Expression Encoder is an advanced application for bringing your edited video project to the web for high-quality playback in Microsoft Silverlight scenarios.

    Also don’t forget to check the Visual Basic Developer Center often for more samples, tutorials, and downloads. We’ll be adding a lot more here in the next month to prepare you for the Visual Studio 2010 launch.

    Enjoy!

  • Beth Massi - Sharing the goodness

    Using Projections with Data Services in Visual Studio 2010

    • 5 Comments

    Starting in Visual Studio 2008 Service Pack 1, you can create ADO.NET Data Services to easily expose data models via RESTful web services. So if you are building a remote CRUD data access layer then this is a technology that you're probably using or are looking into. I’ve written a lot about about data services in VS2008, my favorites are:

    With Visual Studio 2010 and the .NET Framework 4 they’ve changed the name of this technology to WCF Data Services and have added some new features, one of which I want to talk about in this post called Query Projections. But first…

    What’s a Query Projection?

    If you’ve been writing LINQ queries you’re probably writing a lot of projections already. A projection can be used to limit the number of properties that are returned on a set of objects and/or to perform transformations on those properties. This is done using the Select clause. For example, say I have a list of customers that have 12 properties but I only want to return a couple of them in my result collection. I would write:

    Dim result = From c In customerList Select c.CustomerID, c.ContactName

    This creates a list of anonymous types that have only a CustomerID and ContactName property. We say that the query projected these properties from the Customer into the anonymous type. You can also project results into your own known types as well. For instance, say I have a class I’ve defined called MyCustomer with just the two properties defined:

    Class MyCustomer
        Property CustomerID As Integer
        Property ContactName As String
    End Class

    I can write the query so that it will project the results into a collection of MyCustomer objects instead:

    Dim result = From c In customerList
                    Select New MyCustomer With
                           {.CustomerID = c.CustomerID,
                            .ContactName = c.ContactName}

    Take a look here for some Visual Basic and C# query projection examples.

    Query Projection Support in Data Services

    When you write a LINQ query against a data service it is translated to an HTTP GET call. You can use LINQ to query a data service to perform restriction (Where), ordering (Order By) as well as other basic expressions, although not all LINQ syntax is supported. Unfortunately in Visual Studio 2008 SP1 you cannot use a projection (Select) on your queries to a data service, you’ll get a NotSupportedException. This means that all the properties are returned on the data entities you define in your model behind your data service. This can be a drag if you have entities with lots of properties or properties with heavy payloads like images or other binary data. All these must be sent down the wire regardless if you use them or not. Let me show you what I mean.

    I have an Entity Framework model of the Northwind database that I’m exposing via a .NET 3.5 SP1 Data Service just like we built in this previous post. It has Categories and Products entities. The Category entity has a Picture property but I don’t need to use it in my client application. I’ve added the service reference to the client and you would think we could write the following:

    Dim svc As New NorthwindService.NorthwindEntities(New Uri("http://.../NorthwindService.svc/"))
    
    'Try to project just the properties we need:
    Dim result = From c In svc.Categories Select c.CategoryID, c.CategoryName
    
    For Each c In result 'NotSupportedException when query executes
        Console.WriteLine(c)
    Next

    However, we get a runtime error “Select is not supported”. Bummer! In order to project just the properties we need we have to execute the query and bring down the data locally and then project over that list. You can do it in one shot by adding a call to the ToList extension method like this:

    Dim result = From c In svc.Categories.ToList Select c.CategoryID, c.CategoryName

    Unfortunately if you look at the payload you see all the properties returned. So although the result collection is what we want, the way we got it was inefficient on the wire. In our example you can see the binary picture data is returned but never used:

    image

    What we really want is to see just the properties we requested in the payload. Good news is that this is now supported in Visual Studio 2010 and .NET Framework 4. There’s also an update you can install to get this support in .NET 3.5. Let’s explore this new feature by first creating a new WCF Data Service project in Visual Studio 2010.

    Creating a WCF Data Service using Visual Studio 2010

    I want to fist walk though how to create a WCF data service in Visual Studio 2010 since there are some subtle changes in the designers from VS2008. Create a new Project and select the Web node and then choose ASP.NET Empty Web Application. If you don’t see it, make sure your target is set to .NET Framework 4. This is a new handy project template to use especially if your creating data services.

    image

    Click OK and the project is created. It will only contain a web.config. Next add your data model like before. I’m going to use the Entity Framework so go to Project –> Add New Item, select the Data node and then choose ADO.NET Entity Data Model. Click Add and then you can create your data model, in my case I generated it from the Northwind database.

    Next we need to add the WCF Data Service (formerly known as ADO.NET Data Service). Project –> Add New Item, select the Web node and then scroll down and choose WCF Data Service. This item template is renamed for both .NET 3.5 and 4.0 Framework targets so keep that in mind when trying to find it:

    image

    Now you can set up your entity access. For this example I’ll allow read access to all my entities in the model:

    Public Class NorthwindService
        ' TODO: replace [[class name]] with your data class name
        Inherits DataService(Of NorthwindEntities)
    
        ' This method is called only once to initialize service-wide policies.
        Public Shared Sub InitializeService(ByVal config As DataServiceConfiguration)
            ' TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            ' Examples:
            config.SetEntitySetAccessRule("*", EntitySetRights.AllRead)
            ' config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All)
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2
        End Sub
    
    End Class

    Finally, we’ll add a simple client console application to the solution to test the service. File –> Add –> New Project and then select Console application. Right click on the client console application and select "Add Service Reference" in the solution explorer. When the dialog opens click the Discover button and it should find the data service. Name the service reference then click OK. This will automatically generate the client-side proxy and the necessary entities to work with our data service.

    Using Projections with WCF Data Services

    Now that we have a .NET 4.0 WCF Data Service set up we can write a query in our client that specifies the projection:

    Dim svc As New NorthwindEntities(New Uri("http://.../NorthwindService.svc/"))
    
    'Projections now supported in WCF Data Services 
    Dim result = From c In svc.Categories Select c.CategoryID, c.CategoryName
    
    For Each c In result 'No errors 
        Console.WriteLine(c)
    Next

    What this translates to is a GET against our data service that specifies a select parameter that wasn’t supported before. If you open your favorite browser to the WCF Data Service we just created, you can specify a select clause in the query string:

    http://…/NorthwindService.svc/Categories?$select=CategoryID,CategoryName

    Now if you take a look at the payload we can see that only the CategoryID and CategoryName properties are returned from the service, conserving space on the wire:

    image

    For more information on using projections in data service queries please see the MSDN Library and the WCF Data Services Team Blog.

    Enjoy!

  • Beth Massi - Sharing the goodness

    Special EastBay.NET Meeting this Wednesday with Julie Lerman (EF) & Kathleen Dollard (MEF)

    • 0 Comments

    This month we’re having a special meeting day, a week earlier than normal, on this Wednesday March 3rd and you don’t want to miss it! MVPs Julie Lerman and Kathleen Dollard are in town and we thought this would be a great chance to snag them both for a killer session on Entity Framework and MEF with the experts. Here’s the 411:

    EastBay.NET User’s Group Special Meeting
    March meeting – Entity Framework & Managed Extensibility Framework Double Header

    When:  Wednesday, 3/3/2010 at 6:00 PM
    Where: University of Phoenix Learning Center in Livermore, 2481 Constitution Drive, Room 105

    First look at POCO Support in Entity Framework 4
    One of the most important additions to Entity Framework in VS2010 is its support for POCO (Plain Old CLR Object) classes. In this session you'll see how EF is able to support POCOs, how to create POCOs that EF can work with and the difference between super simple POCOs and those which use dynamic proxies at run time to emulate EntityObject behavior such as change notification. We'll also take a quick look at the critical change to EF code generation that allows us to generate and customize POCOs. With POCO capabilities in hand, you will be able to build persistent ignorant, flexible and testable code using entities while still benefiting from the features of Entity Framework.

    The Managed Extensibility Framework (MEF)
    Composable applications are made of building blocks - like Legos. Composability is an extension of many ideas that have fueled architecture evolution in the last twenty years, including isolation, the creation of tiers, and testable applications. Silverlight and .NET now contain the Managed Extensibility Framework or MEF to provide composability. MEF is available in .NET 3.5 and Silverlight 3.0 via downloads and in the box for .NET 4.0 and Silverlight 4.0. MEF is as simple as Import, Export, Compose! You'll learn how do each of these steps with the attributed model to define and retrieve parts in your application. I'll also cover what composability is and the three broad categories - extensions, fully composed applications, and architecturally composed applications. You'll leave understanding when MEF might be a good fit for your applications today and insight into how profoundly MEF is likely to change architectures in the relatively near future.

    Please register here!

    Hope to see you there!

  • Page 1 of 1 (8 items)