Modeling the ‘exactly one of several collections’ case in EF and M

by admin 6/15/2010 8:22:00 AM

For a long time, I have used the ‘totally unique’ power of the Guid to design the ‘exactly one of several collections’ problem in my databases. The Zen case is that of the container in an inventory management system.  The container can be on exactly one of the collection of stores, or exactly one of the collection of trucks, or exactly one of the collection of warehouse locations.  I can’t, in any case, be in two locations, or no location.

image

How I usually implement this is to have a single LocaationId in the Containers table that is of type GUID, and is a foreign key for the TruckId, StoreId or WarehouseLocationId.  Since Guids are globally unique I don’t have the worry about a duplication between tables.  Effectively, the Stores, Trucks and WarehouseLocations tables have an implicit uniqueness constraint, which I can enforce in code if I am getting really squirrely.

I was pleased to see that Entity Framework 4 handles this well.   A “Model from Database” command puts up an entity model that looks strikingly like our domain model diagram.

 

ProtoGuid

All I have to do here is alter the navigation properties to show a single location, but that pass back either a store, truck or warehouselocataion, based on maybe a simple Location interface.  Good enough.

Where I was curious is in learning how M will handle this design.  As it turns out, not as well. I ran the “Model from Database” and got this:

module dbo
{
    export WarehouseLocations, Stores, Containers, Trucks;
    WarehouseLocations : {({
        WarehouseLocationID : Guid;
        Aisle : Integer32;
        Shelf : Integer32;
    } where identity WarehouseLocationID)*};
    Stores : {({
        StoreId : Guid;
        StoreNumber : Text where value.Count() <= 16;
    } where identity StoreId)*};
    Containers : {({
        LocationId : {
            StoreId : Guid;
            StoreNumber : Text where value.Count() <= 16;
        } where value in Stores;
        ContainerId : Guid;
        Description : Text where value.Count() <= 128;
    } where identity ContainerId)*};
    Trucks : {({
        TruckId : Guid;
        VehicleCode : Text where value.Count() <= 16;
    } where identity TruckId)*};
}

Yeah, that wasn’t what I was looking for.  Somehow, the members of Store ended up as values of LocationID as an entity …. meh.  It’s CTP software, but it is worthwhile analysis.  Perhaps I’ll dig in and see if I can figure out how M came up with this after the weekend.

Tags:

M | Biz

VS 2010 Tip: Select error dialog contents

by admin 6/14/2010 5:18:00 PM

 

Back in March when I was testing VS2010’s final versions, I tried to get the contents of a dialog box in order to look up an error.  It’s a small thing, but you can’t copy the contents of dialog boxes any more with the mouse.  I was bummed, so I submitted a Connect ticket:

“It is not possible to select the text in most dialog boxes generated for Visual Studio exceptions. For instance, when attempting to change the network mix in Web Load Tests, the dialog box refers you to a URL at go.microsoft.com for details on administration privileges required. However, it is not possible to select the URL and paste it into a browser.”

As I expected, I was told to go away, they were in RC and weren’t going to add a feature now.  That’s cool.

However, I just got an email from Neelesh on the Load Test team, and he points out that:

“As a workaround you can use "Ctrl_Insert" to copy message box text, paste in notepad and select URL. Kludgy workaround, i agree.”

Kludgy or not, it works great and I’ll use it.

Tags:

C# | VB | Biz

BigInt not recognized in an Access 2007 ADP

by admin 6/9/2010 5:51:00 PM

Anyone who has read my blog or twitter feed, or worked with me, or drank with me, or been in the same room with me for longer that ten minutes, all know that I do not approve of using Access as a business-class development platform.  The technical debt that it creates is not worth the effort, and you end up depending on a software package that is better suited to tracking your recipes than your HR paperwork.

That said, there are some solutions that are well suited for Access, and one of them is form-filling.  In this example, we have an HR department that is required to fill out a form that uses some SQL Server-accessible data, and some entered data.  The resultant paper form has to match a template exactly.

This is the kind of solution that VSTO is actually very good for now, but VSTO wasn’t a reality when the solution was developed, so I give them a break there.  Since the only other real option is to build out a full windows application just to print one form, or to save off copies of Word documents, Access is a decent solution here.

Anyway, back to the problem at hand.  I need to add some fields.  The application is an Access 2007 ADP upgraded from Access 2003, and uses data from a SQL Server 2005 database.  I shift-double-click to enter the editing form.  As I right click on the table to enter design view, I get a surprising error:

image

If you can’t read that, the text says:

"Table 'table_name(dbo)' could not be loaded.

The table being loaded into memory has a user-defined data type ('bigint') that is not recognized.

Close all your open database diagram and table designer windows.  The new data type will be recognized when you re-open the diagram or table designer."

Needless to say, when I close all open windows and re-open them, the problem is still there.

So, usually when I blog about a problem, I have a cool fix.  This time, not the case.  I posted to the partner support forums and got this response:

“Based on my test, I was able to reproduce the issue on my side, if I create a table in SQL directly and open the ADP file associated with the database I see exact same error message when I try to design the table in Access.

create table a1 (id1 bigint primary key)

Also, if I try to create a new table from Access, I cannot find "bigint" in Datatype options.

It seems to be a limitation or issue in Access that it doesn't support bigint in design view though the tables work as expected in other functions.”

That’s kind of a shock: it’s actually a bug in Access 2007.

Anyway, I ended up dropping the table and re-importing from SQL Server which worked fine, BigInt and all.  I have a response in to them as far as finding a better solution, and I wonder if using an ALTER TABLE query might work.  Maybe I’ll roll back and try that.  I’ll post any update here.

Tags:

Biz

SQL Modeling talk at the Central Ohio Day Of .NET

by Admin 6/7/2010 8:12:00 PM

Thanks to Mike Wood and others for asking me to give my SQL Modeling talk at CODODN.  Events like CODODN are important, because the bridge the gab between locla events and the larger regionals like CodeMash.  Smaller groups sometimes mean better hallway conversations and the like.  Kudos to all those who participated in getting this together.

Anyway, here is the solution (WarehouseManagementSystem.zip (2.65 mb)) from my talk.  No slides for this talk, just a little talking and a lot of coding.  Get the bits from the SQL Modeling Website, and make sure you have SQL Express 2008 installed.

 Thanks to all who attended; good questions and insight.

SQL Modeling at the IEEE

by admin 4/10/2010 8:16:00 AM

Thursday night I had the honor of giving my new talk “Software Modeling with ASCII, and no I’m not kidding” to the Columbus Computer society of the IEEE.  They were very welcoming and enjoyed the talk, and had a number of comments about the technology and its use.

I start the talk with what essentially be the first chapter of Professional Software Modeling.  WE cover the problems with current modeling systems, and the timeline for modeling and object/relational mapping

The bulk of the talk is effectively a demo of deploying a database and entity classes form a simple model and then generating an ASP.NET MVC web site from the model.  It is similar to the hands-on-lab at the PDC, with the Mini Nerd Dinner. 

Right off the bat, a listener pointed out that we HAVE these tools already.  Don’t we have XML?  What’s wrong with that?  Tools like WSDL and EDMX solve these problems, and are human readable! Why do we need something else?

I agreed in principle but I pointed out that not many people think that XML is not human readable any more.  The sample code was, but the 150,000 line long files that end up getting used are NOT.  Especially when there are only about 1,500 important lines in the file.

The XML is still there, I assured everyone, and the model was still in EDMX.  M is just a way to work with the model that is a little more succinct than the XML.  Additionally, I pointed out, there are more semantic pieces to M that we hadn’t gone over.  We had done the nouns, but there are verbs too, if you get my drift.

As we went over how an M model looks in the M file, and how the final database and domain classes look, someone asked the obvious question.  It’s the same question that I asked last fall.

“Great!  What do I do with an EXISTING application?”

I don’t have a good answer for that.  Would I like to be able to take an existing application’s database and look at the representative M file?  Yes.  Can I?  I am not sure I can.  That is an open question.

Honestly, I haven’t taken the time to look into the story for existing applications.  Fact is, most application development is adding features to existing applications and I don’t know how M fits into that.  If it is going to be a good modeling tool for existing application there needs to be a reverse-engineering story, and I hope there is.  I mean, you can always make a model from an existing database, but I am not sure that is enough.

The last discussion we had was about potential.  Specifically – what is Microsoft doing to support hte wide adoption of this product?  How about multiple datasources?  What if I need to model an identity system, where there is an Active Directory, an LDS and a database with identity information?  Can I model that in M?

No, I answered.  Right now M is shackled by EDMX, which really only has a provider for SQL Server and Oracle.  It is theoretically possible to enhance the M modeling superstructure to handle a multi-source database, but it isn’t done yet.

In general, everyone loved the talk, and I am looking forward to cleaning it up a bit and giving it a few more times.  Thanks to Jack Freund and the IEEE Computer Society for allowing me to speak!  Hope to see you all again sometime!

Getting started with Identity Services

by admin 4/3/2010 3:20:00 AM

I find myself needing to write a federated identity proof of concept for a client of ICC.  I got started with three downloads:

I wanted to get a good foundation, so I started with the training kit.  As an author, I heavily recommend everyone do this.  The days when you could just jump in and start hacking are long gone.  There are frameworks on top of frameworks in today’s development environments and learning the right path is paramount.

Getting started with a lab

The lab I started with was Web Sites and Identity, becasue it solved the particular problem that I needed solved.  Your might be different.  The prerequisites included:

  • Microsoft® Windows® Vista SP2 (32-bits or 64-bits) , Microsoft® Windows Server 2008 SP2 (32-bit or 64-bit), Microsoft® Windows Server 2008 R2, Microsoft® Windows® 7 RTM (32-bits or 64-bits)
  • Microsoft® Internet Information Services (IIS) 7.0
  • Microsoft® .NET Framework 3.5
  • Microsoft® Visual Studio 2008
  • Microsoft® SQL Express 2005 (or later)
  • Microsoft® Windows Identity Foundation Runtime
  • Microsoft® Windows Identity Foundation SDK

The basics needed to be present, but things like Powershell permissions and IIS 7 configurations have built-in installers that ran easily ran from the dependency checker. 

 

image

You are then asked to install snippets for code and XML.  I put them in the My Snippets folder for Visual Studio 2008.

image

After installing a few certificates, the labs were set up and ready to go.

Working the lab

In working with the lab, it seems that the setup scripts failed to supply the SSL binding for the default web.  I learned a fix in this ScottGu post after making this post to IIS.net

to fix it you just need to go to IIS7 and do these steps:

  1. Select the Default Web Site
  2. Click Bindings… under Edit Site on the right hand command panel
  3. Click the https binding and click the Edit… button

    image
  4. You’ll see that SSL Cert dropdown has No Binding Selected.  Change it to STSTestCert.

    image
  5. Click OK and Close.

That’s all there is to it.  The site will no longer give you Cannot connect errors.

Anyway, I like the lab and I like the WIF.  Generally, it has the same problem as all of the W*F patterns that Microsoft provides.  It is configuration over convention and there are SO many options that it is confusing.  WIF tries to be everything to everyone.  To find the exact situation that suits your needs will require a little digging through the lab.

Columbus Architecture Group

by Admin 3/3/2010 8:48:00 PM

 

I had a good time with the Columbus Architecture Group (ColArc) Tuesday night at the ICC conference center.  I gave the Economics of Cloud Computing talk there and it was well received.

I got some great commentary from Mark Freeman about the impact that CompuServe had on early internetworking, which is a very good point.  CompuServe was born out of TSO, with a large organization reselling unused computer time.  This is very similar to the IBM TSO concept, and what Google, Microsoft, Amazon and the other large players are doing now.

Another point was the impact of grid computing, which I need to research a little more.

One of the big impacts was security, though.  How is cloud going to interact with HIPPA?  how do you convince a CIO?  What else has to happen to prepare your application for the insecurity of the cloud?

Location is a problem too. How about a state’s requirement to keep all data inside its borders?  There are tough questions there!

Anyway, thanks for having me folks, and I hope to see you next month.

Tags:

Biz | Cloud

Parameterizing web load tests

by admin 3/2/2010 8:55:00 PM

You’ve been asked to make sure that the Client Search screen will stand up under load, because it will be most used screen in the application.  You set up a test user, and then run the Web Performance Test wizard in visual Studio 2010 to record the test.  You make a new test project, save it in TFS and add a new Web Performance Test.  the browser launches, and you log in as your test user.  You do a few client searches representative of the use of the system and log off.

Next, you create a Load Test.  The wizard launches, and you prescribe a 50 user test over a half hour.  You save the test, launch it and go to lunch.

When you come back, there are 23,856 errors.

What happened?  Oh, that’s right, one user can’t log into this system more than once – it was an early requirement.  Oh!  How am I going to do this then?  Do I have to record 50 Web Performance Tests? No.  You can parameterize the login.

Making a data source

Start with a CSV file of usernames and passwords.  You can make it in NotePad or Excel.

image

Next, we will need a datasource that points here.  Open your webest and click on the Add Data Source icon up in the test’s button bar.

image

You can select CSV file as the source of the data.

image

Pick the excel file you created and you’ll see the sample data.

image

The new data source will show up as one of the data sources for this test.  Probably shoulda named it something better, huh?

image

Binding the fields

The next major step is to bind the data to the fiends in question.  This is insanely easy.  find the step where you enter the data.  In my case, it was the Login.aspx page.  Open the Form Post Parameters folder and find the parameters for the login and password.  In this app, they are pretty easy to find.

image

Then follow these steps to get to the next image:

Open the properties panel with F4

Click on the fiend in your application that has the user name.  Mine is txtUser_Name

Click on the Value parameter in the properties panel.

Click the dropdown arrow.

Open the data source in the treeview.

Open the testdata table (or whatever you named it)

image

Click on UserName and there you go.  Teat field is now bound to the value.

 image

This will work for any form

Remember, this isn’t just for login.  Actually, I am making a mashup of performance testing and training, adding the training data to the system using the performance test for the New Item pages.  Load testing isn’t just for performance anymore!

Speaking schedule looking good this year

by admin 2/22/2010 2:27:00 AM

 

I have been shooting for one talk a month, and things are looking great for that goal these days.

  • In January, I gave my Economics of Cloud Computing talk at CodeMash.
  • This month I gave Deviant Ollem’s Lockpicking talk,
  • In March I’ll be giving the Economics of Cloud Computing talk to ColArc,
  • In April I’ll be giving my new Software Modeling with ASCII talk to the IEEE and ACM.
  • I have a talk lined up for May, I think.
  • I have talks submitted for TechEd, DevLink and CodeStock so that should give me lots to do for the summer if anyone accepts me.

Then I just have the fall to worry about.  Pretty good year so far!

Tags:

Biz

Modeling and Design

by admin 2/20/2010 7:05:00 PM

Being in the design phase of a large-scale project for the State of Ohio, I have been giving a lot of thought to the problems of Modeling and Design.

You see, I am in an interesting position on most projects – I am an actual Solutions Architect.  In today’s IT environment the term ‘architect’ has grown to mean “good coder with big mouth” and I don’t really fit that mode.  I am not the best coder in the room most of the time – although the size of my mouth could be debated.

What I excel at is the designing of solutions, which leads me to use the term ‘software designer’ to describe myself.  This isn’t terribly good either, as it leads people to believe that I produce pretty graphic design and UX, which isn’t my specialty either.

What I am, in truth, is a Software Modeler.  I am the person that figures out what the domain model looks like based on the requirements of the system and the realities of the project.  The one who stands at the end of the room and scribbles boxes on the whiteboard?  Yeah, that’s me.

Thinking about this has really helped me to hone down the definition of SQL Modeling in my head.  People ask me “Why is Oslo hooked to SQL Server?  Is it just another data language?  Don’t we have enough of these?  I thought M was a language not a database thingie!  Oh woe is me!”  Well, the key is in the difference between design and modeling, and how tightly coupled the model and the database really are.

Software modeling begins and ends with data.  The user interface is, I hate to point out, now the purview of the business analyst.  When I get a functional specification for a project, it has the UI in it right there.  I don’t have to ‘design’ that any more.  All I have to figure out is how to do it.  This effort is modeling, and it is about data.

Today I needed to estimate an inventory system with a few quirks.  Without thinking, I got out my notepad, sketched an ER diagram, and worked from that.  How many POCOs?  How many adapters?  How big is the entity model?  Yes, eventually I had to estimate how long it would take me to build the screens, but the bulk of the work was in the domain model, where the work is done, as it should be.

Livescribe Notebook Page 48

Imagine if I could have instead described my model in text, without all of the brittleness that the ER diagram entails, and have that text description emit both the databases and the POCOs for me?  And then, if something changes, I could change my scratch model and my other code changes?  What if it didn’t break my changes or additions?  What if it didn’t create scores of stored procedures that are impossible to manage? 

Wouldn’t that be nice.

This, though, is the goal of SQL Modeling.  It is clear as day exactly where it fits in the product lifecycle – right there overtop of my fancy notebook scrawls.  Those boxes and chicken feet have a place somewhere, but it’s time for a modeling solution that actually is a solution.

About the author

Bill Sempf Bill Sempf
Author of C# All In One for Dummies (among other things)

E-mail me Send mail

Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Pages

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Sign in