Monthly Archives: October 2007

Mapping Associations in the EDM Designer

I had to figure this out, so here are a billion screenshots so anyone who wants to do this will have an easier time of it!

One of the niceties about being able to customize your conceptual models is not having to bother the dba while they are doing important things like indexing tables and optimizing the database. If you find you have some tables that came into your entity data model that have primary/foreign key relationships that were never defined in the database, then the wizard won’t have built associations for you.

Imagine I have two entities, client and title. A client has many titles (kinda like a publisher but I used a different db for my example, so just live with “client”.) The title entity has a property called clientid. I want to build an association between the two

Right click in the model (white area, not on an entity) and you will get a context menu. Select Add, then Association.

This little window will pop up. It will default the two ends populated with the first two alphabetical entities.

Use the dropdowns in End Entity to change the two end points. I made mine CLient and Title.

The multiplicity options are 1, Zero or One and Many. My relationship is that is one to many, but I can have titles that don’t have a client, so I’m choosing 0..1 for the client and * for the title.

I changed the names of the navigation properties. They started out as Title and Client1. When I’m working with a client, I want to see a property called Titles. (Client.TItles) and title only has one client, so these are the names I want, Titles and Client.

Next is a step that may not make sense but you need to delete the “clientid” property in the title entity. Because of this association, the clientid has a job now and doesn’t belong as a property. (This is debatable and there have been requests to modify this rule for EDMs, but right now, that’s the way it works. You can read more about why in this blog post.)

Now to the mappings. We have told the entities that they are related but they don’t know the basis for their relationship. This happens in the mappings where we wire things up to the representation of the database that is part of the EDMX file created by the wizard.

Right click in the model again and choose Show Entity Mapping Details.

You’ll see an almost empty view, that has only Association and under it <Add a Table or View>. Click on Add a Table or View. Choose one of the entities. This is a little confusing here and I have actually made a suggestion in the forums to simplify it, but just go with the flow.

You’ll get a default that shows the end points you identified in the association and most likely you’ll see id’s on the left and id’s on the right. The “id” on the left refers to the property of the end point. The one on the right refers to the column in the database table (literally the store entity, but db table is easier to grok in this case) that you are mapping to. SO that’s why you see that I have changed my mapping so that client’s id property will map to the client id field in “the other end of the association”, e.g. the Title. Then the title end point (End2) will map over to the id of the other endpoint (client).

Now here’s a small bug with the designer, even if I choose clientid from the drop down list under column, it doesn’t stick (remember, the tool is just a preview right now). I originally had gone into the raw xml to fix this, but thanks to a pointer by Philip in the comments, I see how to get around it more easily.

In the drop down, first choose <Delete>. Then there will be no column mapping for the client end point. Now drop down the list again and choosed clientid. This way it stays.

—————————————
I’m going to leave the by-hand notes in here just for educational purposes.

So I had to doctor this up in the raw xml.

Luckily this was at the bottom of the whole xml file.

<AssociationSetMapping Name=ClientTitle TypeName=EFSampleDatabaseModel.ClientTitle StoreEntitySet=Titles >
  <
EndProperty Name=Title
>
    <
ScalarProperty Name=id ColumnName=id
/>
  </
EndProperty
>
  <
EndProperty Name=Client
>
    <
ScalarProperty Name=id ColumnName=clientid
/>
  </
EndProperty
>
  <
Condition ColumnName=clientid IsNull=false
/>
</
AssociationSetMapping>

I’ve bolded the two changes I made. These were originally “id” because of the mapper problem.
—————————————

The condition exists because it makes no sense to map titles that have null clientids.

Now I can write code like this and see the associations working

Dim oc As New EFSampleDatabaseModel.Entities
Dim q = From c In oc.Clients Select c, c.Titles

For Each c In q
  Console.WriteLine(c.Titles.Count)
Next

Rollo the Pirate says Happy Halloween

I pilfered this from my parent’s website, www.BlueHeavenNewfoundlands.com. They are newfie breeders (mostly Landseers, like Rollo). Rollo is one of their puppies, now 8 years old, who is owned by a really neat lady who dances with her dogs competitively. Yes dances. She and Rollo were even on Nick at Nite and they compete in various “Freestyle” events. YOu can read more about that here. She dresses up her dogs for the dancing and also for pics like these – for Halloween, New Years and more. There’s a page filled with them on my parent’s site.

Silverlight 1.1 – Look before you leap (into LINQ or into WCF)

I spent a lot of time coding in javascript for silverlight 1.0 and am having fun now getting back to managed code with 1.1. I’m even doing it all in C#, but the main reason is because I  have a lot of nearly reusable javascript code and it’s just easier to port that to C#.

However, as usual, I am just diving head first and not doing too much advance research. Two things I learned the hard way:

Silverlight does not yet support LINQ
I spent bunch of time buliding a beatiful LINQ to XML method to build up some XAML by hand. But it was my first time using LINQ to XML to build and XML document, so what I learned in doing that was not a waste by any means.

Silverlight does not yet support WCF
I built a very nice WCF service, with composite types and everything only to learn (when I went to add service reference to my SL client) that it’s not supported yet. There are a few workarounds, [here on the sliverlight forums] and [here in Luis Abreu’s blog], but since this particular code will be for a conference demo and I don’t want to add any extra layers of complexity, I will just go back to ASMX for this one.

Vermont IT Jobs: ASP.NET (and more) Developers in Stowe, Vermont

Yes, you can have it all! Live in a cool place (Stowe, Vermont) and do the work you love surrounded by smart people!

 

(While you are at it, check out Springer-Miller, also in Stowe who, like Inntopia, has a sizable and brainy team of programmers.)

 

 

Inntopia in Stowe

 

APPLICATION DEVELOPERS
REQUIRED TECHNOLOGY EXPERTISE
4+ years experience in a majority of the following technologies

  • ASP.NET/C#
  • SQL/T-SQL
  • XML
  • XSL/XPath
  • AJAX / JavaScript
  • XHTML/DHTML
  • COM/DCOM
  • SOAP/Web Services

SOFTWARE TOOLS
Familiarity with the at least 2 of the following development applications:

  • Microsoft Visual Studio .NET 2003/2005
  • Microsoft SQL Server 2000/2005
  • XMLSpy
  • Visio

REQUIRED SKILLS

  • Ability to design, develop and maintain software on Microsoft .NET platform.
  • Ability to design and develop software in a group or independently.
  • Comfort with direct communication with all levels of technical and business resources.
  • Self-managing, self-motivated learner with good written and oral communication skills.

ADDITIONAL BENEFICIAL SKILLS

  • Travel/hospitality industry experience
  • Experience with high-volume transactional accounting systems (accounts receivable and accounts payable)
  • Experience with complex pricing and commission structures
  • Experience with security protocols (i.e. PCI Compliance and data encryption standards)
  • Experience with software development process management.
  • Experience developing multi-lingual web applications.

Email resume to lisa@inntopia.com

World champs: Boston Red Sox and Lucy the Cow

I’m not a big baseball fan, so I didn’t even realize that the world series was already in play. This morning, I learned that the Red Sox had won yet another series (many Vermonters are big SOX fans) but the really big news this morning was that Lucy, a Holstein from Derby, Vermont, was crowned the “top female Holstein on the planet at the World Dairy Expo in Madison, WIsconsin. “On the planet”!

Here’s the big news with a cute picture of Lucy.

Learn Silverlight Annotation – make a killing in the online advertising market

Yet another Flash driven advertisement (here are some others i’ve blogged about in the past) that uses annotation. Below is a screencast of me playing with this Notes ad (with a mouse, not a stylus). You can do this in Silverlight 1.0 and 1.1 with the InkPresenter. I’ll be giving a session on Annotating in Silverlight as part of the Mobile Connections show during the big DevConnections conference next week (Nov 5 – 8) in Las Vegas.

Article: Writing a Viewer Utility for Crystal Reports

A few years ago, I wrote a little utility for one of my clients who uses Crystal Reports XI to design reports inhouse. They wanted other people on the corporate intranet to be able to see and refresh the reports and if necessary, enter new parameters. Since they weren’t designing reports, it didn’t make sense to buy licenses for everyone and I was able to (very easily) come up with a viewer utility that did the trick. I finally wrote this article about it for ASPAlliance, as they have a great collection of articles (mostly written by Eric Landes).

Writing a Viewer Utility for Crystal Reports