Contents tagged with training

  • Using SQL Metal To Get Connected with Linq

    SQLMetal.exe is the command line tool that will allow you to very quickly spin up the object model you'll need to connect from your SQL Server database via Linq. Here are the basics of using SQLMetal.

    Take a look at this text file, the output from executing SQLMetal.exe from the VS 2008 command prompt with no parameters. It's pretty straight forward but knowing the details ahead of time will help you set yourself up properly.

    To do what I did, you'll need to create a new SQL 05 database on your local machine, call it LinqTesterDB and execute this SQL script to create and populate all the objects.

    The Database
    This database contains a relational dataset with a few tables, a simple DML stored procedure, a view, a table-valued UDF and a scalar-valued UDF. In my next posting we'll look more deeply at what you can do with these kinds of objects and how to properly address them.

    SQL Metal Commands
    The following commands will be executed to show you what we've got. Here is the actual text of what I ran for each example. (The commands are formatted for easier reading. When actually executing, everything should be on one line.)
    1. Create an xml file in dbml format but without an extension so you can peek at it in VS without it opening a designer.
    2. Create a basic dbml file to view and manipulate in the VS designer.
    3. Same as #2 except with the pluralize switch to see what that looks like.
    4. Make the classes generated serializable and include functions, views and stored procedures.
    5. Create just a code file, no designer.
    6. Create a code file and a mapping file but no designer.

    I created new file output names, namespaces and datacontext object names for each example. This allows me to have all of them in the same project at the same time. If I think of it and have time, I'll fire some Linq code up for each example and see what kind of IL is generated for each. I expect it to be the same but it would be nice to know for sure.

    Layout Files
    When you create a dbml file, only that file is created by SQL Metal. Opening or including file in VS 2008 will then create the .layout and .designer.cs files necessary to lay it out. This is great because you can make your layout nice and easy to understand and not have to worry about recreating it every time you have to regenerate the file. If you, like me, use SQL Server's data diagrams, you know the frustration of not knowing exactly when SQL Server will decide to 'rework' your layout for you. This is the file that I reformatted with example #2. Note the table-for-table matching with what's in the SQL database.

    Pluralizing your model notes from MSDN: "When you use the /pluralize option with the Northwind sample database, note the following behavior. When SqlMetal makes row-type names for tables, the table names are singular. When it makes DataContext properties for tables, the table names are plural. Coincidentally, the tables in the Northwind sample database are already plural. Therefore, you do not see that part working. Although it is common practice to name database tables singular, it is also a common practice in .NET to name collections plural."

    Here is an example of the output from using the /pluralize switch.

    Tables, Views, Stored Procedures and Functions
    Note here that including views, sprocs and functions will allow you to see views and operate on them like tables but it will not include table-valued functions in your layout although you can still use them as tables in your Linq queries. Here is a snip of that code:

    var DueDates = from d in db.FnGetDueDates() select d;
    dataGridView1.DataSource = DueDates;

    To Map or Not
    Next, the difference between creating a map file (#6) and not creating a map file (#5) are that not creating the map will force the tool to create an internal System.Data.Linq.Mapping.MappingSource object (concrete type of AttributeMappingSource), two additional constructors for the DataContext and will add attributes directly to all objects and properties as appropriate that will allow them to 'self-map' into the database. See the attached solution for details. By creating the mapping xml file, you take these items out the code file so that if you want to reset any of the mappings, you can. This is a bit closer to an abstraction model but not quite there in my opinion.

    When you run the project, you'll get a button and a data grid. You can fire it up and see the customers in the list executed with only the connection in app.config. Pretty cool. No ADO.Net code or objects anywhere! You can also replace the Linq query and binding with what you see above and bind to a UDF.

    In my next post, I'll spend some time showing how to address each type of object in different ways. Maybe we'll be populating collections or just directly binding to other bits and pieces of the UI that will of course have to expand a bit...




  • Creating and Deploying a Simple Feature

    I found this a week or so ago, lost it and then found it again. At only 29 minutes, its an ideal starter for a develper with my background to create, deploy and activate a feature for a site or site collection. Well spoken and concise with a lot of bits and pieces described in just enough detail to get you working.

    Creating and Deploying a Feature for Windows SharePoint Services V3 - Ted Pattison

    I'm currently working on getting a new page layout into the "12 Hive" via a feature. When I have it nailed, I'll post a how-to. 



  • SharePoint Server Deployment Plan MPP

    Joel Oleson, on the SharePoint Team Blog has posted a sample deployment plan for a MOSS installation. Looks pretty comprehensive.

    At a glance:

    - 6 Months
    - Resources:
       - Database Administrator
       - Desktop Administrator
       - Education/Training Lead
       - End Users
       - Intranet/Internet Administrator
       - Project Manager
       - Test/QA Lead
       - Workspace Coordinators
    - Overall methodology seems to be MSF-esque with phases:
       - Envisioning
       - Planning
       - Deployment, Implementation and Configuration Management
       - Post-Implementation Operations, Optimization and Business Review

    They have clearly tried to make this all things to all deployments which is nice. I expect my shop will probably start out with this and whittle it down a little into something that looks like what we actually do. I think that we'll also set up some task notes or links within tasks to point to specifications and guidance.

    Additionally, this does not cover anything related to significant custom feature deployments. I wouldn't really expect that though.

    Overall, good stuff.


  • Interactive Developer Maps

    I believe that as you age in the software development business, you start realizing that there is very little new in the world. This means that for someone like me who doesn't read very fast and has kids who need shoes, the desire to go out and purchase a new 60 dollar book about the latest technology wanes somewhat. The problem is that half the book is philosophy and half the other half is basic stuff I already knew anyway. Culling through a myriad magazine and internet articles presents the same problem though admittedly without the expense. The authors are often not interesting enough to really keep my attention and the subject matter is frequently a rehash. I long for a diagram that shows me the lay of the land and allows me to just pick out what I want to learn, learn it and move on at my own pace and in my own direction.

    This from the guy who wants to write professionally...

    The MOSS technologies are really a jump forward in my opinion for MS. They offer integration points that "the smart people" are still trying to get their minds around and the products are useful right out of the box. Its like having your own Transformer! What I'm hearing from a lot of people on my team and others, though, is that the ability to actually dig in and code against this beast is limited by documentation. I have to admit, before this morning I got more information from blogs and forums than from any technical articles or books.

    HINT: MOSS and Sharepoint are lumped under Office in MSDN!!

    So I dug around the Office area of MSDN for about 11 seconds and found the Microsoft Office Interactive Developer Map. This is a really cool, easy to follow WPF application! It's available via ClickOnce and gives me both the overview I need to constantly review where I am and the details to let me dig into a piece within context.

    I reallly hope that similar applications are put forth from MS for Visual Studio Team Systems, Exchange, SQL Server and some of the other platforms that have a very high knowledge entry bar.