Entity Framework 6 is coming! Entity Framework 6 is now ramping up for a release. It brings nice Async functionality, but also gives lots more power to the Code First capability, as well as also bringing EF completely out of the core .NET framework - it's instead now a standalone NuGet package. So, the story … Continue reading Meet Entity Framework, the Anti-SQL Framework
A post here on a pattern I thought was obsolete yet I still see cropping up in projects using EF time and time again... What is a Repository? The repository pattern – to me – is just a form of data access gateway. We used it to provide both a form of abstraction above the … Continue reading Why Entity Framework renders the Repository pattern obsolete?
Following on from my posts on dynamic typing… this week I wrote a quick app to import some data from a load of XML files to a load of tables in a SQL database. The columns in the tables and the attributes in the xml file have a 1:1 mapping. So I firstly wrote some code which goes through a given table and reads the schema from the database and creates a C# type based on the schema (using sp_columns). Then I placed a ColumnAttribute on each column etc. etc., and then goes through the task of iterating through the XML data and creating objects of that new type, copy the data across (doing the odd data type conversion along the way), and finally use the standard LinqToSql DataContext to insert the data into the DB. But a lot of the code was somewhat ugly – messing about with TypeBuilders and FieldBuilders and the like – I’m sure that I could have done something much more elegant in C#4…. none of it was compile-time safe, it was all using reflection etc.. But it did work great anyway – apparently was used to migrate a good few thousand records of XML data into SQL relatively quickly 🙂
When installing SQL Express 2008, you may get the following error if you already have VS 2008 installed: Rule “Previous releases of Microsoft Visual Studio 2008” failed. A previous release of Microsoft Visual Studio 2008 is installed on this computer. Upgrade Microsoft Visual Studio 2008 to the SP1 before installing SQL Server 2008. I’ve read a load of blogs about this issue, but none of them solved the problem that I was having, as I already had VS 2008 SP1 installed. Galin Iliev’s excellent blog post comes close but doesn’t quite hit the bullseye (although I believe that his solution would probably work as well). The problem is that I have Visual Studio 2008 database edition installed as well. So, from Galin’s post, I found that the following registry key stores version settings of VS: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\VS\Servicing\9.0 Going in there, I see not one, but three sub-keys: - I’ve annotated the above with what I guess the different keys represent. Inside each of those keys are a load of properties, one of which is named SP. VSTD is set to 1 (correctly), but VSDB and VSDBGDR are both set to 0. Solution: Ensure that all three keys have the “SP” value set to 1. It appears that the SQL installer expects all of them to be set to 1 otherwise it won’t install… P.S. Probably best to set them back to 0 after the install 🙂
So, I installed SQL Express 2005 only to find that when removing SQL Express 2008, and then manually removing those two components (2008 object model and 2008 native client) that I’d somehow “broken” 2005 (even though I hadn’t yet installed it!). I guess there are some assemblies that are overwritten by the 2008 install that are backwards compatible – so when I uninstalled the 2008 items that the 2008 uninstall left behind, it screwed me completely. So, reinstalled them – and finally got SQL Express 2005 working. Until I accidentally changed the default database for my Windows account to my custom database that I was working on and then deleted it by accident! Now I can’t even log in to SQL. So I had to use SQLCMD to log in and change my default database back to master. Phew…. all this just to prepare a demo of a few features of C# 3 and LINQ!
I was looking for the SQL Express 2005 edition and came across the 2008 one. So I thought I’d give it a try – what a waste of time! Ran the installer for SQL Express 2008 Wouldn’t install because I didnt have the latest version of Windows Installer (4.5). Downloaded Windows Installer 4.5 Installed Windows Installer 4.5 Rebooted Wouldn’t install because I didn’t have Windows Powershell installed Downloaded Windows Powershell Installed Windows Powershell Ran the installer for SQL Express 2008 Wouldn’t install because I didn’t have Visual Studio 2008 SP1 installed – except I did! Gave up after this and just got the old 2005 version of SQL Express. But not before I had to manually uninstall half of the rubbish the 2008 installer left behind on my PC.
I ended up using ClickOnce deployment instead of Windows Installer after all! This is because I uninstalled the beta of VS2008 and installed the "proper" version of VS 2008 Express - which doesn't support Setup projects. ClickOnce is fairly easy to set up - the only thing that I couldn't work out was how to get it to notice Content files in dependant projects for deployment purposes i.e. the .sdf file that is the database for the application is in another project, and doesn't get picked up by the ClickOnce publisher. So I had to move the .sdf file into my main project that is published - not ideal but not the end of the world. I have also then found that after installing and running the first time, occasionally after the install, the database file can't be found by the application. Once you run it a second time, it works fine - but the first time on install it doesn't always work. Weird.