RSS Top50
Login Form
| RSS Name: | ||
Welcome to the 'Entertain us' Nation | ||
View All articles |
Recently posted:
- A new venture in China [2010-03-07 04:31:52]
- Using the Entity Framework v2 to Query for a specific value using Dynamic SQL [2010-03-07 04:31:52]
- ?of mice and men and SSIS Packages.. [2010-03-07 04:31:52]
- Notes from the back of a napkin [2010-02-19 03:38:41]
- Feed Me! [2010-02-19 03:38:41]
- Farewell Queensland [2010-02-06 06:19:48]
- Mass Effect 2 ? Game Review [2010-02-02 03:20:43]
- No article today? [2010-01-28 10:07:23]
- Next Steps with SQL Azure [2010-01-27 07:03:49]
- Putting it all together ? SQL Azure [2010-01-27 07:03:49]
A new venture in China (view original)
[Post Time: 2010-03-07 04:31:52]As some of you already know we have decided to live in China and study Mandarin and have arrived tonight in Shanghai. We put our belongings into storage and made our final trip to New South Wales last week. Today (3/3/10) we left Sydney for the orient.
My wife and I are going to be living in the beautiful city of HangZhou which is 1.5 hours by train south west of Shanghai.
Despite the relocation, I intend on continuing my technical entries and tinkering with all things .Net (well, all technology really).
view original back to top
Using the Entity Framework v2 to Query for a specific value using Dynamic SQL (view original)
[Post Time: 2010-03-07 04:31:52]Well for a while today, I?ve been trying to find a way to execute a specific dynamic query with the Entity Framework ? a query which could be used on a variety of different tables.
I have a series of tables which share a common column definition (lets call it ?DateEnd?, of type DateTime). Our example use case scenario is that we might want to query one of the several tables for the most recent value for this common column.
So normally what we would create is something akin to the following (where Table is set dynamically):
SELECT TOP(1) [DateEnd]
FROM [<table>]
ORDER BY [DateEnd] desc
Now, the main problem here is how can you execute such a query within the constraints of the Entity Framework?
If you?ve investigated the API you?ll find it isn?t necessarily obvious how we would proceed.
The first problem is that the design ties it strongly to mapped entities (as opposed to scalar values), and secondly the syntax ties it heavily to explicitly typed (using EntityTypes) queries where you have to know the base type at compile time ? i.e. the following LINQ query requires we specify the source table at compile time:
DateTime mostRecentDate = (from d in db.Statistics
orderby d.DateEnd descending
select d.DateEnd).Take(1).FirstOrDefault();
Luckily, I have a solution which will achieve the desired result!
The answer is to make use of the data ObjectContext.CreateQuery<T>(..) method.
With CreateQuery, we must specify the expected type (in our example, we use DateTime). We can create our query as you would normally expect ? here?s a sample:
Note that values in italics should be the name of your DataContext type.
using(ContextName db = new ContextName())
{
string currentTable = ?Statistics?;
string query = String.Format(?select value c.DateEnd from {0} as c order by c.DateEnd desc?, currentTable);
DateTime query = db.CreateQuery<DateTime>(query).FirstOrDefault();
}
Now, here?s the trick ? the query has to be specifically formatted. A straight T-SQL compatible query won?t work!
Let?s examine the example query from above:
string query = String.Format(?select value top(1) c.DateEnd from {0} as c order by c.DateEnd desc?, currentTable);
The two values in bold, above, are needed. We have to specify that we are returning a value (hence, the first highlighted word) and then we must use the qualified object name ? not the table name. In other words if you are pluralizing tables in your model, the table ?Statistic? would be ?Statistics? ? and therefore you would need to use ?Statistics?. Also note that the column used uses an alias (c.).
Now if we profile (trace) our query you can see it successfully queries as we would expect:
So if you are getting something along the lines of this error message:
?[..] could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly. Near simple identifier, line 1, column [..].?
It most likely means you aren?t correctly using an alias. Make sure you are using a table alias and prefixing it where appropriate.
Now you can go query mad! Just kidding, please use this wisely. Unfortunately, this method makes it possible to execute unwieldy queries against the data store directly. So please use it very sparingly, and only if Stored Procedures or Functions are not appropriate to your scenario.
Cheers?R
view original back to top
?of mice and men and SSIS Packages.. (view original)
[Post Time: 2010-03-07 04:31:52]Today I have been modifying a very repetitious SSIS package which does bulk import of data form a flat file. The Data Import Wizard is a pain when you want to import the same format but from different source files, especially since it is unstable and tends to crash when you make changes and try to re-run its SSIS package.
So I created a package using the Wizard, then created a new Integration Services project in Visual Studio 2008 (no word on when support will be added for SQL Server projects in VS 2010?). I imported (add existing item) the package the Wizard created and started to much around with adding variables so that I could set the input file path and the destination table name before executing the SSIS package in question.
The power here is we only have to set column definitions and the schema of the destination once, rather than having to re-jig every time we go to (manually) import from a flat file. Below is what the wizard-generated SSIS package looks like:
The package created by the Wizard uses a hardcoded table name (for the destination) and input file paths (pointing to the source flat file) ? so in order to work around this I had to do the following:
- change the hardcoded destination table (which is defined in a Script task) to something generic
- add a second SQL Task which renames the generic table to the value we want from config
- add a configuration for the package (so I can set the source path and the destination table name)
So here is the Control Flow of the package, now modified, from the original rendition:
The second task simply calls a system stored procedure to rename our ?generic? table (in this example called, tmp) to a name set by configuration:
Note here that I have created a User defined variable which is then set via configuration. Speaking of configuration, how does one go about establishing an external config file for an SSIS package? Actually, it?s quite easy..
Right click your package designer and select ?Package Configurations??. Create a new configuration, and use the wizard to specify the location to store the file, and the settings you wish to override via the configuration. It?s all very simple, I?m not going to go into detail here. You can see the settings in the screenshot below.
You can also set the values of your Data Source components ? in the case of the flat file connection manager, this is the ConnectionString property. Anyhow, hope this entry helps any of you who are lost in overriding SSIS settings using configuration!
R
view original back to top
Notes from the back of a napkin (view original)
[Post Time: 2010-02-19 03:38:41]Last night I had a good night out with some former colleagues in Canberra. It was thoroughly enjoyable to talk on a technical level whilst also engaging in the usual developer-consuming-alcohol banter (surely you know what I mean, yes?).
It brought to mind some thoughts I had been contemplating some two years ago, relating to being a technical consultant. So, I thought I might write down some of these thoughts and share with the community.
One of the most difficult aspects of being an IT consultant is the business support you get on an engagement from your own company.
There is often little to no technical oversight on an engagement, and if something negative occurs between client and consultant then the consultant is placed in a very difficult position indeed. Sales people typically are non-technical and therefore in many situations would not be ideal in backing up the consultant in the field.
So what is the answer?
The most obvious course of action is to promote senior IT Consultants and have them monitor various engagements including the handover/wind up of an engagement. This gives the consultant in the field some backing if the engagement fails or if the client becomes unreasonable (or consistently changes the scope or goals of the engagement).
However, this rarely happens as the consulting company usually doesn?t want to pay for such resource allocation ? especially as senior IT consultants tend to be expensive and rare resources.
Is there another option?
Yes, the second potential consideration is to clearly define each engagement. Although this might be too much work form some sales people, it would really give technical consultants a chance to complete an engagement to the satisfaction of all parties concerned. Unfortunately, the nature of the beast is that a technical project can not be easily defined in such terms up front without significant cost to either the client or the consulting firm, and so rarely happens.
Why do people/companies refuse to pay for detailed technical estimations?
Well, the answer to this is most likely what you?d expect ? no matter how detailed the ?envisioning? phase of a new IT project, there is still no sure fire way to estimate the absolute cost of a project. Whether you choose top down or bottom up estimation, at the end of the day it is still only an estimate. Businesses are hesitant to spend even a few hundred dollars on this kind of technical due diligence.
Why don?t companies provide quotes?
Well, for much the same reason that companies prefer not to pay for technical estimations, most consulting companies would prefer not to invest their consultant?s time (and thus, the consulting company?s own money) at a project that they many not land. Under estimation is rife in the IT industry as many competing companies try to produce the lowest quote.
So, can you summarise the above for me?
In essence, we have a situation where consultants are often deployed onto engagements with limited technical oversight, coupled with a limited definition of the work involved and probably without the due diligence required to ensure a successful outcome.
In order to secure more positive outcomes for IT projects a number of changes need to occur.
The most obvious is that companies need to get smarter and better prepared when considering a technical project. Simply opting for the cheapest quote without doing some investigation and comparison between vendors would force vendors to produce more detailed estimations/quotations. At the end of the day, the Latin term ?caveat emptor? applies, and typically companies get what they pay for.
Consulting companies need to come to terms with the fact that they need to cover the cost of properly supporting their experts in the field. A burnt engagement is typically the product of more than one factor, but blaming a sole consultant in the field is at best ill sighted and at worst professionally negligent. Relying on IT consultants to ?set customer expectations? in isolation are not being fair to either the consultant or the client.
It would also help if IT consulting companies would stop selling their consultants as ?experts in any field?. It places an unfair amount of pressure on an IT consultant to ?read a book about technology X? the night before starting a new engagement. This happens more than you might think.
Lastly, a consensus needs to be brought forward during each project that ensures all stakeholders are receiving the detail and frequency of status updates which keeps everyone in synch. Good channels of communication and trust needs to exist from the highest level to the lowest. Businesses at war with each other rarely thrive.
Anyway, I hope this provides food for thought.
view original back to top
Feed Me! (view original)
[Post Time: 2010-02-19 03:38:41]Apologies, at the moment I am ?on the road? ? a nomad if you will ? and as such, it has been rough finding time to put together some new technical articles for your enjoyment. Last week Microsoft released the ?Release Candidate? version of Visual Studio 2010 and Team Foundation Server 2010 and I have spent some time investigating the new releases.
Check back in early March, once we?ve settled down again and there will be more articles ? so check back soon.
view original back to top
Farewell Queensland (view original)
[Post Time: 2010-02-06 06:19:48]It is with a sigh of relief that we are packing up our possessions and calling our ?experiment? in Queensland officially over. This should come as no surprise to anyone who knows us well, and who would also be aware that our time up in the Sunshine State over the past two years has been far from harmonious.
The past two years have been a rocky and, in some cases, disastrous time in which we have failed fairly miserably to connect with the local community, It has also been rough going both personally and professionally for the both of us.
Although it is tempting to call the time spent here a complete write off; there have been some wins - notably by way of International travel (Europe), a new car (a 98 Mercedes SLK) and through the upgrading of our lounge room. We have had great support from our interstate family and friends (you know who you are) and specifically from my friends Derek, Sylvain (best of luck in New York in 2010!) Deepak, Trish and Paul.
We are moving out next week and spending some time in New South Wales before heading overseas for the rest of 2010. Check back for future blog posts, I?ll continue to blog wherever adventure takes us?
Looking ahead, I may be available for presentations, technical architecture and assorted professional consulting depending on the location and the fee ? especially in the Asia-Pacific region. If you are in China, Hong Kong, Japan or Singapore (including KL and Malaysia) and need some high caliber technical work (especially consults) please don?t hesitate to get in touch.
If you are interested in getting in touch with me you may reach me at rob.sanders@gmail.com (put ?Blog? in the subject line). I?m going to be roaming for a while, but this gives me excellent availability for short term work.
view original back to top
Mass Effect 2 ? Game Review (view original)
[Post Time: 2010-02-02 03:20:43]A few years ago Canadian games developer BioWare brought us the critically acclaimed ?Star Wars: Knights of the Old Republic? and later followed with ?Jade Empire? and, more recently, ?Mass Effect? and ?Dragon Age?.
In 2010, BioWare (now owned by Electronic Arts) has released the long awaited sequel to Mass Effect in the form of Mass Effect 2. If you are not familiar with the former (Mass Effect) I will briefly give you an overview, before looking at the sequel (skip this next section if you are already familiar with Mass Effect).
Overview of Mass Effect 1
In essence, Mass Effect (1) brought much of the core game play values of Knights of the Old Republic to a non-Star Wars universe. The game is a role playing game combined with a first person shooter engine, which allows details such as weapon customization, assignment of skills and technique to team members and an almost infinite combination of choices and modifications making each play through somewhat unique. Players choose various ways to react to the main storyline (and side missions) which come with consequences accordingly.
In this new Mass Effect universe, Star Wars? ?force powers? are represented by ?biotic powers? and many of the characters are also highly adept with technical skills alongside the more traditional soldier roles.
In terms of storyline, the main character in the series is a human called Shepard (first name is configurable) who can be played as a male or female. You start the game a member of an ?Earth Alliance? which is struggling to join a sort of interstellar council (of other races). As Shepard, you must investigate the exploits of a rogue council agent who is believed to be behind attacks on Alliance territory. As a special operative for the council (a Spectre) you get to operate with a wide degree of latitude. Juggling the demands of the Alliance with the politics of the council is no easy task!
Needless to say, should you survive until the end, you?ll realize that the story effectively ends as a sort of cliffhanger, in preparation for the second installment.
Looking at Mass Effect 2
At the beginning of Mass Effect 2, the story essentially picks up from where the original ended. In order to sustain a JJ Abrams? style ?reboot?, your character (Shepard) is killed off in the opening sequence which, as you might expect, is not really the end of the line for our hero. Your character is re-engineered courtesy of a shadowy organization called Cerberus which is mentioned a few times in the first game. You are given a new ship (very similar to your ship from the first game, with a few surprises) and, in essence, a new squad to train and build upon.
In terms of plot line, and without giving away too much information, the essence is that human colonies are being attacked again, but this time people are being abducted. A race called ?The Collectors? are found to be behind these mysterious raids and, as usual, the council disavow the attacks. Cerberus and Shepard must act to save the human colonies from these attacks. That?s pretty much what you might see from the surface.
In reality though, this is a far more detailed game.
Groundwork
One of the interesting things about Mass Effect 2 is that, should you have saved games from the original, you can import them into the new game. This is a really excellent feature and one which is really well executed. Characters from your first play through in Mass Effect (1) come back in various ways throughout the game in Mass Effect 2, depending on decisions you made in the first game.
I?m a huge fan of continuity as it is such a reward for those who have been loyal to the franchise. Those who have not played Mass Effect will likely miss a lot of these sly references (such as spam e-mail from Morlan!).
The New Team
Although you will cross paths with many of the main characters from the first game, you?ll mostly acquire brand new team mates in Mass Effect 2. This is a great move, as it unlocks a number of surprising options, and even more interesting topics/dialogue. Each team member has a specific advantage, and skill set, which can become invaluable during the game.
As with the original, a lot of the game is driven by dialogue with other characters, although you do not acquire experience points from such discussions. Although the rationale behind detailed dialogue remains the same as in the first game (interesting concepts and topics), in some cases it is essential to find out as much as you can to complete a mission. Despite this (in general), those who want to shoot things and talk later are not disadvantaged.
Game Quality
What really drives up the quality of this game is the solid voice acting. There are some big names behind some of the characters including Martin Sheen as the voice of the infamous ?Illusive Man? - the man behind the curtain, running Cerberus. You?ll also potentially recognize Australia?s own Yvonne Strahovski from TV?s ?Chuck? mainly as the programmers modelled her character to look like the actress herself (as a brunette).
There are also solid contributions from support vocals, I?d have to say (without doing a disservice to the quality of the former title) that the sounds, look and feel of Mass Effect 2 are markedly better than in the original release.
Changes to game play
BioWare have made a number of big changes to game play in the sequel. The inventory system from Mass Effect has been removed and replaced with a significantly cut down version. This is a little disappointing as it makes the game less customizable, although far more manageable. Basic stock weapons are ?upgraded? via a number of ways (purchasing at stores or finding weapon research in the field). A note on upgrades ? talk to your team mates. They may have many helpful suggestions!
Also gone are heat based weapons, in favour of an ammo-based system (known as heat clips). This is troublesome if you are unable to find ammo (especially for heavy weapons). I found it was more of a problem at the start of the game when your character is significantly weaker than later in the game. As the number of enemies increases, so does the available ammo. It would be nice to be able to purchase ammo from stores, or to have ammo automatically replenished when you return to the ship.
The combat system has also changed slightly. It now resembles more of a ?Gears of War? style. Your team mates have a tendency to run into open ground probably a little too much for my liking or, in some cases, they seem to fall back and abandon you. These are minor quibbles, in general the battles are challenging and bug free. A mix of tech, biotic and weapon attacks gives you plenty of variety to spread around.
Also, character profiles are reduced. There are less skills and abilities to upgrade over the course of the game and player levels are fewer. On an initial play through it is not really possible to gain higher than level 28 or so, whereas in the original you could make it to around the high 40s. This is not altogether a bad thing, but it does make starting out a little tough.
Some quibbles
In addition to what I?ve listed above, I had a couple of concerns as I was playing through the first time.
My main concern was over weapon customization. Depending on your character?s class (something which defines the nature of your character?s main skills) initially, you are restricted to a small number of offensive skills, powers and weapons. You broaden this base as you progress through the game.
If you are restricted to, say, hand pistols and sub machine guns it can be frustrating that you can?t find weapon upgrades for these items in the early stages. Assault rifle/shotgun/sniper upgrades seemed to be far easier to acquire, but you needed to pursue specific missions to unlock weapon benefits for the initial weapons ? this seemed to make it a lot harder in combat, when you?re firing a weapon which has had no upgrades.
I?d suggest that it should be possible to purchase a wider variety of powerful weapon upgrades from stores dotted throughout the Mass Effect landscape. Furthermore, as a Spectre (see Mass Effect 1) you should be able to obtain a wider range of powerful weapons (as you could in the first game).
This isn?t by any means a show stopper, but I?d really be encouraged by some changes to this aspect of the game. What we ought to see is some sort of middle ground between the inventory of Mass Effect 1, and the reduced (streamlined) approach in Mass Effect 2. It would be nice to have options for both casual non-RPG style play and a more RPG focused approach (if possible).
More Reading
This has been a relatively short review focused on a number of key areas. If you are interested, I?d strongly suggest this review posted on Slashdot, which does a great job of explaining a few more concepts.
Summary
A solid game which will take many hours to work through. In terms of ?re-playability?, you could play this game right through about two or three times and discover new things each time. It?s addictive fun, and if you liked the first game, you?ll love the sequel. Highly recommended.
view original back to top
No article today? (view original)
[Post Time: 2010-01-28 10:07:23]It seems like I?ve been on a bit of a roll lately talking about SQL Azure and the Entity Framework (v4). I intend to delve deeper into the Entity Framework v4 in coming articles. We will be taking a closer look at POCO (Plain Old CLR Object) support as well as self tracking objects, improved Stored Procedure support and lazy loading options.
We will also revisit SQL Azure as it enters production (next month). We?ll look at some administrative options as well as SQL Management Studio 2008 R2?s ongoing interoperability.
For the moment, I?m a bit preoccupied, so I?ll be taking a short break but the articles will resume shortly. In the meantime, please leave comments and/or feel free to shoot me an email if you have questions! I?m only too happy to help if I can.
Best
R
view original back to top
Next Steps with SQL Azure (view original)
[Post Time: 2010-01-27 07:03:49]Following on from my previous posts (check them out before continuing) ? this article assumes you have followed steps outlined in the previous posts to create various models and accounts etc.
|
Introduction
So now that we?ve had a look at some of the basics around SQL Azure, Microsoft?s Database in the cloud, let us take a look at something more practical. For our next example, I?m going to refer to a schema I designed and populated last year ? my vinyl record collection. You can have a look at the details of the schema in a previous entry - Project Sneak Peek.
The project was previously defined in this entry - New Project Announcement: SqlAzure Database and Azure Application (though we may skip the Azure application part, depending on time).
Given the schema is for SQL Server 2008, one of our first tasks will be to script the database and existing data, and then convert it to be conform with SQL Azure?s T-SQL restrictions.
Generating Scripts with SQL Management Studio 2008 R2 (November 2009 CTP)
Let us take a quick look at the first step ? scripting the existing database.
You may skip this step and use the script I?ve attached (at the end of this post) if you wish, or you can download the pre-migration script and follow along.
There?s nothing tricky here except that some of the options have changed.
Once you?ve created the Database on a SQL Server 2008 instance (using the script provided, at the end of this post) right click the Database and select ?Generate Scripts..?.
When the ?Generate and Publish Scripts? wizard loads, you?ll notice that the initial screen has from the 2008 RTM version.
This is a ?cut down? version which heavily simplifies the process of generating a script. Click ?Next?.
From the radio buttons, change it from the default setting, select ?Select specific database objects?, and then check the checkbox next to the Tables item in the tree view, below. Note that the ?Script Data? option is no longer here, it has been merged into ?Types of data to script?.
From the next screen ? do not click ?Next? just yet. Click the ?Advanced? button first.
Change the defaults to the values specified in the screen below.
Once everything is set, you may click OK and then proceed to generate the script.
Once the script has been generated, you?ll need to make some changes to the T-SQL, as it will not be compatible with SQL Azure by default.
Making a SQL Azure Compatible Script
For this purpose, I recommend downloading the following tool from CodePlex - SQL Azure Migration Wizard v3.1.4.
The other option is to connect to SQL Azure via SQL Management Studio R2 (Beta) and parse the script whilst connected to SQL Azure. The tool is the better option IMHO.
If you use the tool, once it is running, select the ?Analyze and Migrate? option, ?TSQL File?. Note, you could also migrate an existing schema (but where would be the fun in that?).
Select the source file and click ?Next?. you?ll see a very busy window and a lot of T-SQL generated. Once it is finished, you can select the contents and save to a new file or simply hit the save button. Either way, you should now have a valid T-SQL syntax for SQL Azure.
Following the steps from the previous post, you can now connect to SQL Azure and run the script to generate the database. A quick short list of steps follows:
- Through the Azure Developer Portal, create a new Database
- Open SQL Management Studio 2008 R2 and connect to the SQL Azure Database
- Open the script with the active connection
- Parse the script (to check for any issues)
- Execute the script (ensure that the first statement is Use [Vinyl])
- Verify no errors, and that all data is added
Stay tuned for the next article, as we?ll discover what we can do with our new Database in the Cloud.
Database Scripts
SQL 2008 T-SQL Script
SQL Azure T-SQL Script
Further Reading
- SQL Azure enhancements with SQL 2008 R2 - http://www.mssqltips.com/tip.asp?tip=1898
- Windows Azure Tools for Microsoft Visual Studio (November 2009)
Tools and References
view original back to top
Putting it all together ? SQL Azure (view original)
[Post Time: 2010-01-27 07:03:49]Happy Australia Day to you!
Following on from my previous posts (check them out before continuing) ? this article assumes you have followed steps outlined in the previous posts to create various models and accounts etc.
|
Now we should have a working data model which has been created in your SQL Azure (Cloud) database. Taking lessons learned from Part 2, we?re going to create an Entity Framework (v4) model of the SQL Azure tables using Visual Studio 2010 Beta 2.
This entry is sort of a rehash of the first and second entries, but the outcome should provide you with a fully functioning Entity Framework (v4) data model, and a Unit Test to prove it works!
Creating the Model
Fire up Visual Studio 2010 (Beta 2). Next use ?File ?> Project..? and choose a new Class Library. You can name the new Library whatever you like, but I will be calling it SQLAzure.Application.DataAccess as you can see in the following screen shot:
Now, the first thing I do when I create a new solution or project is to add a corresponding Unit Test project, so we can code out some Unit Tests as we implement new functionality. Let?s do that now.
If you can?t see it, the Solution node in the Solution Explorer can be set to ?Always Visible? by going to ?Tools ?> Options?, ?Projects and Solutions? and check the checkbox next to ?Always show solution?.
Now, right click the ?Solution? in Solution Explorer and select ?Add New Project?. You want to select a new Test Project (select the Test node under the tree list on the left hand side). I?ve called my test project SQLAzure.Application.DataAccess.UnitTests. Once added, right click on the ?References? solution folder and select the DataAccess project. You?ll also need to add a reference to System.Data.Entity.
Now, let?s delete those default files added to the projects (Class1.cs and UnitTest1.cs) which should leave us with a fairly vanilla solution, like so:
Now let?s configure that Data Model! In the DataAccess project, right click and ?Add ?> New Item..?. Select ?Application Configuration File? then press ?Add?.
Note that the file opens in the Text Editor after it has been added. Copy and paste the following code between the <configuration> tags, then replace the items in bold with the proper values for your SQL Azure database:
<connectionStrings>
<add name="SqlDataModelContainer" connectionString="metadata=res://*/SqlDataModel.csdl|res://*/SqlDataModel.ssdl|res://*/SqlDataModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=[servername].database.windows.net;Database=Vinyl;Uid=[user]@[servername];Pwd=[password];""
providerName="System.Data.EntityClient" />
</connectionStrings>
Next, on the DataAccess project, right click ?Add ?> New Item..? and select ?Data? from the left hand tree. Name the file ?SqlDataModel.edmx? and click ?Add?. On the next screen, select ?Empty Model? and then click ?Finish?.
A blank model will open in the editor. Now, assuming you?ve followed all these steps correctly, you should be able to right click the model and select ?Update Model from Database??.
You should find yourself looking at the ?Update Wizard??s ?Choose Your Database Objects? window. If you are not, it means your App.Config probably has incorrect values. Refer to my first post for how to fix any issues you may encounter.
Select all the Tables in this dialog and click ?Finish?. Barring any unexpected errors, you should now be looking at a fully articulated Entity Framework model of the schema we previously created and populated in SQL Azure.
Save the file and close it.
Verifying it all works!
Now, right click on the UnitTests project and select ?Add ?> New Test..? and select a ?Unit Test?. I typically add a ?Smoke Test? set of tests which look for basic connectivity and authentication. You can see from the following screen capture:
Next, remove all the template generated plumbing (you won?t need it for these basic tests, and rename the initial test to be now called ?BasicDataAccessTest?, as follows:
Now, we?re going to need to add a config setting. We?re going to add a link to the App.Config file you created under the DataAccess project. Right click the UnitTests project and select ?Add ?> Existing Item..?. Browse to the App.Config file under the DataAccess project (you may have to change the file filter to ?All Files (*.*)? to see it). Instead of clicking ?Add?, click on the little downwards arrow on the Add button and select ?Add As Link?.
Now, a reference to the DataAccess? App.Config exists, thus no need to duplicate the connectionString settings across multiple projects, just one config for all.
Next, copy the following code into the body of the BasicDataAccessTest function (you will need to add ?using System.Diagnostics;? at the top of the file): (apologies for a lack of colouring)
[TestMethod]
public void BasicDataAccessTest()
{
using (SqlDataModelContainer e = new SqlDataModelContainer())
{
var albumsCount = (from a in e.Albums
select a).Count();
Trace.WriteLine(String.Format("Total records found: {0}", albumsCount));
}
}
Now, click on the Test menu and select ?Windows ?> Test View?. You might need to click the little ?Refresh? button to see the renamed Test Method.![]()
The proof is in the pudding
Assuming you?ve followed all the steps thus far, you should be able to successfully run this test now. If you double click on the test result, you should see the following:
If you haven?t managed to get this test to pass, then you must have some problems with your configuration. Re-read this entry and you should manage to have it all wired up correctly. Please drop me an email (rob.sanders [at] gmail.com) if you encounter any issues, I?m more than happy to try and help.
Conclusion
Now, assuming you have achieved success in wiring up this simple Unit Test, you have a working data model and working SQL Azure database instance. Congratulations!
In my next article, I?ll show you some of the more complex queries we can perform, as well as begin to introduce you to some of the amazing functionality which is now available to use, because you have a working Entity Framework (v4) data model.
Check back soon for the next entry.
view original back to top
"Welcome to the 'Entertain us' Nation"Hot articles:
-
Fine.. I'll go build my own theme park
......(5-28 14:17, Hits: 555) -
Custom List: Out of Print DVDs
......(1-2 09:12, Hits: 212) -
Photo Album: PhonePix
......(4-25 11:24, Hits: 200) -
Photo Album: 30 December - Grange
......(12-30 11:23, Hits: 195) -
Why Vista? The Good, The Bad, The Ugly - Part 1
......(1-22 17:33, Hits: 180) -
Friday on my mind...
......(2-16 14:56, Hits: 179) -
Custom List: Favourite TV Shows
......(12-1 15:46, Hits: 174) -
Movie Trailers!
......(5-3 09:16, Hits: 174) -
Book List
......(11-14 13:57, Hits: 173) -
Photo Album: 04 December
......(4-25 11:24, Hits: 166)
