Skip to main content

EndInTiers - Chris Hewitt's Blog

Go Search
Blog
Articles
  

Other Blogs
There are no items in this list.
ADO.NET for Silverlight

On the 13th of May I presented a talk to the VIC.NET Dev SIG on the topic of ADO.NET for Silverlight. The talk was one day after the release of Visual Studio 2008 SP1 Beta1 so I promised to post the PowerPoint and demos later when I had them working with SP1. Silverlight 2 Beta 2 still hasn't been released but I have the first couple of demos re-done. You can download these from the following links:

PowerPoint Slides (2007 pptx)

Flights Database (SQL Server 2005 Backup)

Demo 1 - Entity Framework (VS 2008 SP1 B1 zip)

Demo 2 - ADO.NET Data Services (VS 2008 SP1 B1 zip)

Demo 3 – Winforms Client (VS 2008 SP1 B1 zip)

Demo 4 – Silverlight Client (VS 2008 SP1 B1/Silverlight 2 Beta 2 zip)

 

Later (soon J) when Silverlight 2 Beta 2 is released I'll add the WinForms and Silverlight client demos

Demo 1 - Entity Framework

The first demo was creating an Entity Model from a database. The database (Flights) is very simple. There are only 3 tables:

These tables are mapped directly into three EntitySets in the Entity Model but additionally for a bit of bling I added a direct many-to-many relationship between Passenger and Flight and an Inherited Entity AvailableFlight. The discriminator for AvailableFlight is the IsAvailableFlight column from the Flight Table.

There are a couple of points to note here:

  1. The discriminator Column for the Inheritance relationship (IsAvailableFlight) can't be an identity or computed column. Trying to use a computed discriminator gives you a validation error:
    Error 2016: Condition cannot be specified for Column member <column> because it is marked with a 'Computed' or 'Identity' StoreGeneratedPattern
    But IsAvailableFlight makes more sense as a derivative of MaxSeatsAllocatedSeats so I cheated and implemented a trigger on the Flight Table that recalculates IsAvailableFlight and RemainingSeats whenever MaxSeats or AllocatedSeats are updated.


    CREATE TRIGGER [dbo].[Flight_Updated]

    ON [dbo].[Flight]

    AFTER INSERT,UPDATE

    AS

    BEGIN

        SET NOCOUNT ON;

    IF UPDATE(MaxSeats) OR UPDATE(AllocatedSeats)

    UPDATE dbo.Flight SET RemainingSeats = ins.MaxSeats - ins.AllocatedSeats,

    IsAvailableFlight = CONVERT(bit, (CASE WHEN (ins.MaxSeats - ins.AllocatedSeats > 0) THEN 1 ELSE 0 END))

    FROM inserted ins

    WHERE Flight.FlightID = ins.FlightID

    END

     

  2. There is already a relationship in the model between Passenger and Flight via the two one to-many Associations and the Seat EntitySet. If you try to add the additional many-to-many Association again using Seat as the mapping table you get one of the following errors for each association:
    Error 3034: Problem in Mapping Fragment(s) starting at line(s) <lines>: Data loss is possible. These two partitions are equal in the storage model but not in the conceptual model. Check that both ends of the AssociationSet are mapped to the corresponding columns.
    I fixed this by adding a view of the Seat table to the database and using the view as the mapping table for the PassengerFlight many-to-many association.

As part of the EF demo I also showed some funky LINQ to Entities queries that made use of the Inherited Entity. That was from Readify's new PRO.NET 3.5 course so I can't post that code here. We will explore some of the inheritance options in the Client-Side code in later Demos.


Demo 2 – ADO.NET Data Services

The second demo was exposing the Entity Model using ADO.NET Data Services. This is very simple – you just add an ADO.NET Data Service to the project and then change a couple of things in the template class, first the parent template so the class definition becomes:

public class FlightsDataService : DataService<FlightsModel.FlightsEntities>

Then set some security rules. In this case I have set them as follows:

config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);

config.SetEntitySetAccessRule("Seat", EntitySetRights.WriteAppend | EntitySetRights.AllRead);

config.SetEntitySetAccessRule("Passenger", EntitySetRights.WriteAppend | EntitySetRights.AllRead);

 

config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);

 

The DataService does not have any ServiceOperations available so the permissive "ServiceOperationRights.All" doesn't really cause any problems. The Entity Set Access rules allow anyone read only access to all the EntitySets and allow new Passengers and Seats to be added – the significance of this will become clearer in later demos.

I then demoed a number of REST queries in a browser. If you want to try this yourself you will have to turn off the feed reading view in IE so you can see the raw data.

When you browse to the service you see a list of the supported entities. http://endintiers.com/FlightsService/FlightsDataService.svc

 

If you want a list say of the Passenger entity set you can browse to: http://endintiers.com/FlightsService/FlightsDataService.svc/Passenger

 

To retrieve a particular Passenger you need to use the EntityKey, try: http://endintiers.com/FlightsService/FlightsDataService.svc/Passenger(1)

 

All the flights for Passenger 2

http://endintiers.com/FlightsService/FlightsDataService.svc/Passenger(2)/Flights

 

All the passengers on Passenger 2's Flight 1

http://endintiers.com/FlightsService/FlightsDataService.svc/Passenger(2)/Flights(1)/Passengers

 

Only AvailableFlights

http://endintiers.com/FlightsService/FlightsDataService.svc/Flight?$filter=isof('FlightsModel.AvailableFlight')

 

Passengers whose FirstName contains Ch

http://endintiers.com/FlightsService/FlightsDataService.svc/Passenger?$filter=contains(FirstName,'Ch')

 

You can start to see the power of this URI-based query syntax. Any Entity can be accessed via HTTP: retrieved (GET), inserted (POST), deleted (DELETE) or updated (PUT). Client libraries are available for .NET, AJAX and Silverlight.

 

If you were awake you may have noticed that those links above actually do something...there is a demo service running on my Blog server....

 

Coming soon: The WinForms Client and the Silverlight Client (when Silverlight 2 Beta 2 finally drops).

Building an Australian Home Server

I have done quite a bit of research on Home Server hardware, and have come to some conclusions. The major conclusion is that in terms of value for money you can't beat HP's MediaSmart Home Server, which retails for around US$600 (A$685). However the HP unit is not yet available in Australia. When it eventually is it should be possible to buy it for around A$750.

In the meantime, what if you are in Australia and want to build your own version of the MediaSmart Server? You could use the following (similar) bits:

Case: Chenbro ES34069 Mini ITX Home Server Case can take a 2.5" system disk and up to four hot-swap SATA II .5" disks – its not much bigger than the 4 drive caddies and is silent (external power supply). Takes mini-ITX and mini-DTX motherboards.

A$400

Motherboard: I decided to go with the KINO-761AM2 mini-ITX motherboard. I am trying to duplicate the HP which uses AMD (I suspect actually an AMD690T chipset), but this one is cheaper than many and has just enough SATA II's (and DIMM not SODIMM).

A$270

CPU: Since we are in AMD land, we can use the Athlon 64 2000+, which has a TDP of only 8W.

A$90

 

Memory: 2GB of Corsair 667

A$69

 

System Disk: WD 80GB 2.5" IDE

A$80

The Chenbro can take a single 2.5" system disk as well…actually an improvement on the HP.

First SATA Disk: WD 500GB SATA II 16MB

A$130

Room for 3 more….

OS: OEM Windows Home Server
A$200

 

Total: A$1,240

 


So I have managed to build a replica of the HP system for only A$500 more…obviously not a great idea, so plan 2, using larger more common/cheaper bits.

Case: Antec NSK3480 Bigger than the Chenbro and HP, but not that big – this is a real mini-ATX case,  is quiet and comes with an 80+ efficient power supply.
A$130

A$130

SATA Drive Cage: Unlike the Chenbro, the Antec doesn't come with an internal hot-Swap drive bay, so I'll add an ICY DOCK MB453SPF. Fits in 2 x 5.25" bays, takes 3 x Hot Swap SATA II drives.

A$120

Motherboard: The Gigabyte GA-G33-D2SR has 6 SATA II Ports, supports Raid 0,1,10 and 5 and comes with a handy eSATA bracket.

A$150

CPU: In an attempt to minimise heat/power usage I'll go with an Intel E2140 CPU. Uses a bit more power than the AMD, but not much and is quite powerful.

A$80

 

Memory: 2GB of Corsair 667

A$69

 

System Disk: WD 500GB SATA II 16MB

32GB used for System Disk, rest is storage.

A$130

 

SATA Disks: All bays empty to start with.

A$0

Room for 3 more SATA disks…

OS: OEM Windows Home Server
A$200

 

Total: A$880

 

 

A$880 is more like what we would expect to pay for the HP Server when it comes out, so what are the advantages/disadvantages of doing it this way (as opposed to waiting for the HP system to arrive)?

Advantages:

  • Choice. You can use any mini-ATX M/B and CPU you like
  • Capacity. I have gone for the smallest case I can get, but you could use a larger case and get any number of hot-swap SATA II's.
  • Timing. You can have one of these now.

Disadvantages

  • Power usage. The E2140 uses 20W or so more than the AMD Sempron 2000+
  • Lifetime. With smaller cases thermal design becomes very important, while the Antec has good thermal characteristics I would assume that the HP is better, which will lead to longer component lifetimes.

Conclusion:

I'm not very good at waiting, so I'm going to build one of these (Antec variant) for myself.

ADO.NET Entity Framework Talk

I did a short talk on the Entity Framework at SQL Down Under CodeCamp yesterday. Big thanks to Greg Low for organising the event. You can download my PowerPoint from here. If you are interested the sample app is here and a backup of the database is here.

Of course you will need VS 2008, EF Beta2 and EF Tools Beta1 to open the example...

Readify Developer Network Launches

The Readify Developer Network is alive after a long gestation. I must say I like the name (it was the one I voted for). Greg Low has a full description of the offering here. But basically it will give us lots of opportunities to learn about new technologies, a reason to learn up on new technologies and practice at presenting on new technologies...it's all good.

WinForms Report Explorer for SharePoint Integrated Reports

The Report Explorer SQL Server example doesn't work with SharePoint Report Integration. This is mainly because it uses the ReportingService2005 web service rather than ReportingService2006.

As well the SQL Server sample uses the WinForms ReportViewer control, which seems (I didn't look too closely) to have problems with SharePoint hosted reports.

This sample uses the ReportingService2006 and ReportIngExecution2005 Web Services to render reports from SharePoint in a WinForms app.

SO and WCF Talk from CodeCampOz

 

I put my Service Orientation and WCF powerpoint (pptx) and demo application up here just in case anyone is interested. If you are really keen you can get a backup of the the db too!

I'll try to drill down and explain some of the issues here over the next couple of months.

Antec Fusion VFD in Vista

If you have an Antec Fusion case and have installed Vista, you may notice that the VFD doesn't work.

I couldn't find anything about Vista on the Antec site, but the new drivers can be downloaded from the manufacturers of the VFD (and the knob) at: http://www.soundgraph.com/Eng_/main.aspx.

Happy HTPC'ing!

 

Using Forms Authentication in WSS 3.0

I am in the process of setting up a public WSS Server for MDNUG that uses Forms Authentication. I mentioned this to Ed Richard from MOSSIG who suggested that I blog about it, so here goes...

This post attempts to describe as simply as possible how to change a WSS V3.0 application to support Forms Authentication. It assumes that you already have a Site Collection that uses integrated security created.

  1. We are going to use the Microsoft SQL Server Membership Provider (AspNetSQLMembershipProvider). First we need to create a database to use; this is done by executing an application called aspnet_regsql.exe on the target server. The application is located in your .NET Framework directory under the Windows directory. Ours for example is in the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 directory. The application takes you through a short 'wizard' - the key dialog is the following where you set the SQL Server name (SQL Server 2000 or 2005) and the database name.

     

     

  2. Override the default LocalSqlServer connection string to point to our new database. We could use our own uniquely named connection string but then we would need to register our own provider and we are trying to keep it as simple as possible...Add the following to the web.config of the target site (after the </SharePoint> tag would be fine):

     

    <connectionStrings>

    <remove name="LocalSqlServer" />

    <add name="LocalSqlServer" connectionString="Data Source=(local);Initial Catalog=WSSASPNETDB;Integrated Security=SSPI;" />

    </connectionStrings>

     

    Note that this connection string uses integrated security. In order for this to work you will need to give the user that is the identity of the Application Pool that your target Website runs in has permissions to access the database that you created. Another option would be to use SQL Server security and embed the userid/password in the connection string.

     

  3. Create at least one user in this database (which will be the Site Administrator) before we change the authentication. There are a number of ways you can do this, for example if you have a copy of Visual Studio 2005 installed on the server (which you shouldn't) you can use the ASP.NET Web Site Administration tool. In our case we are going to use a WebPart created by Matthew Cosier hosted on one of the pages in the existing site (we are going to need this somewhere later anyway if we want people to be able to register for the site and create a login).

     

     

  4. Override the default LocalSqlServer connection string of the SharePoint Central Admin Website to point to our new database. Add the following to the web.config of the SharePoint Admin site (after the </SharePoint> tag would be fine):

     

    <connectionStrings>

    <remove name="LocalSqlServer" />

    <add name="LocalSqlServer" connectionString="Data Source=(local;Initial Catalog=WSSASPNETDB;Integrated Security=SSPI;" />

    </connectionStrings>

     

    Again this connection string uses integrated security. In order for this to work you will need to give the user that is the identity of the Application Pool that SharePoint Admin runs in has permissions to access the database that you created. Note that this only works well if there is only one Forms Authentication WSS site on this machine, if you want to have more you will have to use a more complex method (out of context for this article).

     

  5. In SharePoint Central Administration, change the Authentication Provider for the target Web Application from Windows to Forms, enable anonymous access, and set the Membership Provider and Role Manager to the ASP.NET default providers.

     

     

  6. Sign on to the Site Collection as Administrator and allow Anonymous access

     

     

  7. Change the Administrator of the site from the Integrated Auth user to the user you added to the database in step 3). If you set the LocalSqlServer connection string in SharePoint Administrations web.config properly and if the pool identity that Central Admin uses is permitted access to the new membership database then when you click check on the people picker it should be underlined. This makes our new Forms identity Admin for the Site Collection.

     

     

  8. Now when you go back to the site you should be able to log in as the user you added to the DB and specified as Site Collection Admin you should be able to perform all admin functions.
Chris finds his ‘groove’

It's been a long time since I wrote a blog article – in the meantime I've tried a lot of blogging technologies looking for something that is:

  1. Easy to use
  2. Malleable

Nothing seemed to fit; there are lots of easy to use sites and tools out there but what if I decide I want my comments to look slightly different – or maybe I feel like 'improving' commenting workflow J...

Well hopefully this is my solution...I'm using the new Windows SharePoint Services V3 Blog Site Template (which I can modify at will) in combination with Word 2007 and Vista as in the following diagram (which will be automatically uploaded into my SharePoint content DB for me by Word!):

Note that the blogging stuff is part of WSS V3 - a free add-in for Windows Server 2003, so no need to buy a copy of Office SharePoint Server 2007 to support this.

 ‭(Hidden)‬ Admin Links