All posts by Julie

Using Entity Framework entities as Data Sources in a WinForms App

I’ve done this demo many times in conference and user group sessions. Someone on the ADO.NET forums asked how to do it and I thought I would just do a quick tutorial with screenshots.

What this Tutorial does is demonstrate how to create and use a data source from a particular entity in the model. I’m just doing simple drag and drop and no filtering or anything here with the goal of just a quick basic walkthrough for getting started.

Start by creating a Windows Application.

Add an Entity Data Model.

Select Data from the menu and choose Add New Data Source

In the first page of the wizard, choose Object as your Data Source Type.

The next screen of the wizard will show the namespaces in the current solution. Open up the namespace for the application

then choose the entity which you want to use as a Data Source. I will pick customer.

Then you can Finish the Wizard.

Now to get easy access to the datasource, go back to the menu and choose Show Data Sources from the Data menu.

The DataSources Window will be placed in your IDE in it’s default location. Mine docks with the windows on the left.

When it’s not pinned it gets tucked away with the others. You can undock it and put it wherever you want.

I can now drag and drop the customer data source onto the windows form to get the automatic DataGridView and Navigation toolbar (this is normal behavior for DataSource and not specific to Entity Framework).

There are a few more steps to actually getting user interaction with this. You need to populate the Binding Source and if you want to edit, you’ll need to add a little code to the save button on the toolbar.

You’ll need to enable the BindingNavigatorSaveButton (just click the save icon on the navigator toolbar and change it’s Enabled property to True). Additionally, you’ll probably want to format the grid which you can do easily from it’s SmartTag and more thoroughly through the properties window.

Here’s what the code behind looks like in my form enabling me to view, add, delete, edit and save data.

Imports WindowsApplication1.AdventureWorksLTModel
  Public Class Form1
   Private aw As AdventureWorksLTEntities
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
     aw = New AdventureWorksLTEntities
     CustomerBindingSource.DataSource = aw.Customer.OrderBy(Function(cust) cust.CompanyName)
   End Sub
   Private Sub CustomerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, _ 
   ByVal e As System.EventArgs) Handles CustomerBindingNavigatorSaveItem.Click
     aw.SaveChanges()
   End Sub
 End Class

Note that because the AdventureWorks Customer table has the following constraints: ModifiedDate must be a valid date value and the PasswordHash and PasswordSalt fields cannot be Null, I have extended the entity class to take care of these things when SaveChanges is called.

“Astoria” (ADO.NET Data Services) CTP Released

Finally it’s real live production bits to play with!!

In addition to finally using real bits, key to this release are the finalization of response formats (XML by way of ATOM and JSON), security, an AJAX client, querying with LINQ when you are using one of the clients. THere’s a lot more.

Mike Flasko published 4 blog posts on the Astoria Team weblog yesterday:

ADO.NET Data Services (“Project Astoria”) CTP is Released

Viewing Data Services Responses Using Atom Serialization in Internet Explorer

ADO.NET Data Services Dec2007 CTP – Validation and Access Control

LINQ to ADO.NET Data Services

 

Tasha, the 14 year old (that”s 98 to us!) Newfoundland dog

While I was at my parent’s house helping out with their THIRTY-FOUR new newfie pups, Tasha was at home hitting an amazing milestone! She turned 14 years old. This is very old for a newfie. While she isn’t the athletic young girl she used to be thanks to arthritis, she is still full of it! Barking every morning to make sure everyone in the neighborhood knows “I’m still here!”, eating like a champ and full of desire (though not the ability) to go down to the road and see what there is to see. I spent years keeping her from getting hit by cars. Now that she’s old, I finally don’t have to worry about that any more. Her eyesight and hearing seem to be fine and she gets acupuncture to help out with the arthritis since her back legs are quite stiff. It’s hard to get up, get down and to walk. Not so hard that she’s not willing though although she hasn’t been doing stairs for a few years now. Every day I watch her so carefully to make sure that I’m not being selfish.

Here’s a picture of her today. A little scruffy because it’s basically impossible to give her a bath as we can’t make her stand for a long time. We can’t get her upstairs to our easy access shower to try to bathe her there either and now it’s too cold to bathe her outdoors. But she doesn’t mind and neither do we. She’s 98!

A little less than four years ago, I took some pics when we were giving Tasha a bath at our local (wonderful) pet store that has a great setup. Even then she was old for a newf at 10 and standing for a long time was a little problematic. But look how cute she is!

No less amazing is Daisy who will be 13 in a few more weeks.

ScottGu on how to deal with the Microsoft firehose

At the Mix n Mash  earlier this week, I asked Scott Guthrie what his opinion was about developers having to deal with SO many new technologies coming out from Microsoft at such a rapid pace.

His recommendation was to pick what is core to your work, or what you are really good at or really vested in and then ignore the rest.

Easier said than done.

Even if we follow ONLY his blog, we have myriad technologies in our faces. It’s very hard to predict the future. I am currently “ignoring’ .NET 3.0 (WPF, WCF & Workflow), MVC, AJAX Control Kit, SQL Server 2008, a huge chunk of Silverlight. Granted MVC is far out. Volta just showed up. Astoria is plowing ahead without me at the moment. Surface is astounding. And there’s so much more.

It’s very frustrating because this isn’t Lays potato chips. The one I ignore may have been the one that will make a difference in my ability to support a future client.

What Scott is suggesting is akin to watching t.v. without a remote! 🙂 We’ll see how it goes…

Second Litter puppy pics

(On going… you can catch up at www.blueheavennewfoundlands.com)

The second litter was born yesterday. I’m helping to watch over them today. Celeste has to feed them every two hours and they nurse for over 1/2 hour. In between everyone rests up and the puppies get a Snuggle Puppy to curl up with. These are more than toys as they have a heartbeat and are warm. Sometimes they are all underneath it. Here’s what they are doing right now (there are 6 total but you can’t see them all here). The upstairs puppies (the litter of 17 that is now two weeks old) get two Snuggle puppies!

Vermont InstallFest and Bob & Chris RoadShow was a big success

Although I wasn’t able to be in Vermont on Thursday for the Bob & Chris Roadshow or the VS2008 Installfest, I have gotten emails from Chris Bowen and others letting me know that it was a great success. Over 40 people showed up for the installfest, and I learned from Dave Burke’s blog that they also had TWO XB0X 360’s set up for folks to play with.

Larry Keyes blogged his extensive notes from the day.

Sorry to have missed it.

What I really enjoyed reading was Dave Burke’s epiphany about VS2008. The sessions from Bob & Chris really made things click for him and he’s ready to get in bed wiht VS2008. I was thinking about that becasue he said he’s seen LINQ 4 times before, but not until Thursday did he finally get to his AHA! moment with it. I believe this may have a lot to do with the fact that it’s finished, it’s deployed and in hand, rather than seeing very early bits (we’ve had 3 LINQ talks at VTdotNET in the last 1 1/2 years).