Powerd by dasBlog RSS 2.0
 Saturday, August 23, 2008

I’ve been looking at a couple of the new technologies that were released with .Net 3.5 SP1, mainly the Entity Framework (EF), and ADO.Net Data Services ADNS). I happen to look at ADO.Net Data Services first, and it seemed to look pretty good on paper. There was a reference to the Entity Framework in that Data Services uses the Entity Model (EM) from EF to provide the data access layer.

Last night I started searching for more information on the Entity Framework, and instead of finding examples, best practices, etc, I found a battle waging between the Creators/Supports of the Entity Framework and people practicing what I have come to know as Alt.Net.

I am using the term Alt.Net to refer to ideas and concepts such as Domain Driven Design (DDD), Test Driven Development (TDD), Agile, Plain Old CLR Objects (POCO), Persistence Ignorance (PI), and nHibernate (as there is allot of comparison made to the EF). I should also note that the ideas and concepts listed are not entirely specific to .Net, nor is this a complete list. Furthermore, you could be a practitioner of Alt.Net and completely support EF.

To get an idea of where the Alt.Net crowd is coming from you should start off by reading the Vote of No Confidence on WuFoo. Then simply Google for Entity Framework and you will see all sorts of competing opinions. Frans Bouma, creator of LLBLGen Pro, has a couple of posts (here, and here) that I think show he is against the EF, but for slightly difference reasons then the Alt.Net crowd. Here are some of the top Pros and Cons I’ve found.

Pros:

  1. It’s support by Microsoft, and as such, will gather much momentum and community support
  2. It’s good enough for X% (usually stated as greater then 50%) of software projects out there.
  3. GUI editor/mapper makes it easier to use then other ORM tools like nHibernate
  4. EF is part of a larger push by Microsoft to provide technologies that focus on an Entity Model (See Ado.Net Data Services)

Cons:

  1. No support for POCO’s and Persistent Ignorance
  2. Hard (or impossible) to develop using a Domain Driven Design, or Test Driven Design methodology
  3. Single model/mapping file introduces merge conflicts in a source control environment
  4. No additional functionality of products like nHibernate

I kind of see Pro #1 being the cornerstone to the argument. I feel that the Alt.Net crowd knows that EF has a good chance to become the defacto standard, and that they will be forced by their clients and employers to use it. As such, they are trying to point out some of it’s short comings to Microsoft in hopes that if it does become the defacto standard, that it won’t suck (to them) as much.

The EF team has been very open with the community, and reading posts leading up to the release of the EF, you can already see that the team was listening to the community. They introduced something called IPOCO, which removed the requirement that Entity classes implement a base class, and instead implement interfaces. This pleased some, while it annoyed others, since it still breaks true Persistent Ignorance.  I feel it’s a step in the right direction.

There are other indications that V2 of the EF will introduce true Persistant Ignorance, although the EF team usually talks about a performance hit (and it sounds like it could be a big performance hit) if you want to go the POCO route. The reason for this is the lack of the EntityKey field in a POCO object, which is used in subsequent operations after an entity is retrieved from the framework.

Overall, I find myself smack dab in the middle of the two camps. I’ve been trying to explore and learn more about Alt.Net, while at the same time keeping up on the latest from Microsoft. I’ve come up with the following guidelines for myself.

  1. Since EF is not support in Compact Framework, and I need to write business entities for the Compact Framework, or one’s that can be used in both the Full and Compact Frameworks, EF is out (so is nHibernate for that matter).
  2. If I need to work on a new back end application that is going to be using SQL server exclusively (there is support for other data stores in EF), then EF might not be a bad way to go.
  3. If I need to work on an existing back end application, I don’t think it’s worth the time to switch to EF yet, as it’s still a V1 product.

In the near term, I see my self doing some CF programming, as well as some one-off programming against our backend, which gives me a nice blend I guess. I’ll get to play around with EF some, and keep exploring the ideas of Alt.Net.

One final item I’d like to point out is the Entity Framework Contrib Project on CodePlex. While it hasn’t had a release since before RTM of the EF, it does provide some very interesting additions to the EF. The one that interests me the most, might just in fact be the bridge between the EF and POCO that everyone is looking for. Using PostSharp, the IPOCO interfaces are implemented at compile time, thus keeping your entities persistent Ignorant. The trade off is that you have to add some attributes to your code, but at least you could add these conditionally, which would help with the CF/FF issues I have.

Unfortunately the main contributor has taken a job and Microsoft on the SilverLight team, and in response to the EF’s team to add POCO support, has lost some of his interest in the project. I really like the post compile time option that the contrib project uses, as it seems to address the performance hit that the EF team says their POCO solution will have.

Saturday, August 23, 2008 7:51:13 PM UTC  #    Comments [0] - Trackback
Programming | Review For Future Projects
 Sunday, August 17, 2008

With the release of all Visual Studio 2008, TFS 2008, and SQL 2008, I set about upgrading I set about upgrading my main development laptop. Currently I have VS 2008, Team Explorer 2008 and SQL 2005 client tools installed. I opted to download the full installer for the SP1 updates as opposed to the bootstrapper options.

I knew I needed to install VS 2008 SP1 prior to TFS 2008 SP1, but for some reason decided to go with the SQL upgrade first. As I mentioned before, I currently only have the client tools installed, as I like to keep my SQL servers on virtualized development servers.

The SQL 2008 installer starts off by checking for .Net 3.5 SP1, and if it does not exist, it will install it on your machine, along with a hotfix for windows installer. After this is complete, you are required to reboot your machine. I opted for the upgrade option, hoping that everything just works. I’m not sure if you can do a side by side install with SQL 2005 client tools and 2008.

After selecting my options, an upgrade check is preformed, and it failed because I have not installed VS 2008 SP1 yet. OK, I wanted to install that anyway, so I canceled out and launched the VS 2008 SP1 installer. As with most service packs for Visual Studio it takes awhile to apply, but my experience was more positive then the service packs for VS 2005. No reboot was required, so I moved onto the TFS 2008 SP1 install.

So I must have mis-understood or did not read something with the TFS 2008 SP1 installer. It looks like it’s for the server components only, and VS 2008 SP1 handles upgrades to Team Explorer as well. This blog post makes reference to this, and even says that if you are installing Team Explorer on your TFS server, to install VS 2008 SP1. Looking at Help/About Microsoft Visual Studio, I see the version number for VS 2008 is now 9.0.30729.1 SP, and looking at the details for Team Explorer shows the same version number.

Jumping back to the SQL 2008 installer, I proceeding with my update. However it wasn’t really an update as much as it was a side by side install. Remember, I was just doing the client tools, had I had the database components installed, I assume that those would have been upgraded. I have a couple of SQL 2005 instances I can try an upgrade on to see what happens. The install went very smoothly and there were no issues.

First impressions of the new SQL Management studio are extremely positive. I saw the intelli-sense demo at the launch event, but can’t really test it as I already have SQL Prompt installed. My job as a Pseudo-DBA just got easier.Here are some new features I found.

  • When running queries, you can view the results in traditional grid view, but also as text (with options to choose your column delimiters), or export to a text (.rpt) file.
  • The new activity monitor actually provides useful information (well alot more information then the old one ever did). It reminds me of the task manager in Windows Server 2008. The new activity monitor does not work with SQL 2000, but I will be eliminating all SQL 2000 boxes by the end of September. As 4 line graphs across the top you get % Processor time, Waiting Tasks, Database I/O and Batch Requests/Sec. On the bottom you get 4 collapsible lists: Processes, Resource Waits, Data File I/O and Recent Expensive Queries.
  • The database publishing wizard from Visual Studio is now included. Actually there are a lot more options to control how your scripts are generated.
  • There are some very nice default reports built in now as well. The reports were an add-on for SQL 2005, but they are now included (and you can of course write your own). Stuff like Disk Usage, Index Usage, etc. I hope I can find a way to schedule these to be emailed.
  • New option to generate Create and Drop Script (along with the original separate options of generate create and generate drop). There is also an option to generate as SQL Agent job.

Finally I went ahead and upgraded our TFS server to SP1. First thing I did was install this month’s Windows Updates, as I was going to have to reboot anyway. Next up was Visual Studio 2008 SP1, as I have VS and Team Explorer installed. Unfortunately I was out of room on my system drive so I had to take the extra step of expanding my virtual hard disk first.

I rebooted the server, and then proceeded to install TFS 2008 SP1. It looked like everything was going good, but it failed at some point. Turns out the SQL server did not survive the reboot, VS 2008 SP1, or the system drive expansion. Somehow my mssqlsystemresource.ldf file got messed up at some point. The event log error stated “One or more files do not match the primary file of the database.”. I got better information out of the SQL error log which pointed me right to the System Resource ldf. I copied the ldf file from another SQL 2005 server and was back in business. The TFS update proceeded without incident after that. In case you are wondering, you can determine your TFS version by looking at the version of Microsoft.TeamFoundation.Server.dll in %Program Files%\Microsoft Visual Studio 2008 Team Foundation Server\Web Services\Services\bin. For SP1, the version number matches that which is displayed in Visual Studio 2008, or 9.0.30729.1.

Sunday, August 17, 2008 12:00:32 AM UTC  #    Comments [0] - Trackback
Technology | Programming | Sql
 Wednesday, August 13, 2008

My weekly Code Project newsletter had a link to a submission which talked about, and rated various Aspect Orientated Programming (AOP) frameworks for .Net. While I’ve heard about AOP in the past, I haven’t looked into much. What got me off the side lines, was that one of the .Net AOP frameworks, Post Sharp, lists support for the Compact Framework and Silverlight. In my experience, it is rare to see stuff that actually supports the compact framework, so this is a welcome change, however I have not tested it out yet.

Before I dive into Post Sharp anymore then I have, I wanted to read up a bit on AOP. WikiPedia has a good article explaining the AOP using AspectJ as the example language. PostSharp itself has a an article that focuses on the .Net Framework as well.

What is Aspect Orientated Programming (AOP)?

  • AOP increases modularity by allowing the separation of cross-cutting concerns
  • A concern is a cohesive area of functionality (think encapsulation).
  • Cross-Cutting concerns are those concerns which are used in multiple concerns
  • Logging is the most typical example of a cross-cutting concern. It itself is a concern (encapsulated functionality), that is used everywhere in your program.

Examples of Cross-Cutting Concerns

  • Logging
  • Exception Handling
  • Tracking is dirty on fields
  • Auditing
  • Security
  • Transactions

How does it work (based on Post Sharp)

  • Implement cross-cutting concerns as classes creating attributes (implementing various interfaces in Post Sharp)
  • Decorate your code using your attributes. Attributes can be added at the method, field, class and assembly level. At the class and assembly level you can specify a filter specify which methods or classes to work on.
  • When you compile, Post Sharp performs post build processing injecting code into your compile MSIL, producing modified MSIL as the final output.

AOP Frameworks

Performance

I was originally under the impression that by injecting code at compile time, there would be no performance hit at run time. This is not true, at least in PostSharp using the simple performance test from the user provided samples.

The simple performance test sample shows that AOP using Post Sharp incurs a variable performance hit. Running the sample application multiple times shows the first time the post sharp code is hit (view the complied .exe in reflector) it takes 73ms, and then this drops down to 14 ms, compared to 4 ms for the non PostSharp code. On subsequent runs, the first access of the post sharp code takes ~21ms and then drops down to 14ms, while the non PostSharp code remains at 4ms.

The sample in question uses the works on a field in a class. The aspect (attribute code) is required to cast an object passed in by the event args to a string. Perhaps generics could help with performance by eliminating the cast?

Final Thoughts

AOP and PostSharp look like very powerful tools that I would like to take advantage of. Learning from my past mistakes, I need to make sure that I take the time to understand these tools and use them where appropriate and not go overboard with their use. I think a good first step would be to find, or write some examples that implement some basic AOP functionality covering all of the cross-cutting concerns identified above.

The only complaint I have so far is that you have to either install PostSharp on your computer, or manually edit every project file that needs post processing. This seems a little heavy handed, but I’m willing to consider it a fair tradeoff. It just makes it hard to do a strictly x-copy deployment of a project/solution.

I’ve also been reading up on software architecture, including topics on Separation of Concerns and Loose Coupling. I think it is obvious that AOP can help with the separation of concerns (it’s pretty much stated in the definition). I also get the feeling that it could help with loose coupling, but I haven't seen a good example on that yet. All the examples I have seen would require tight coupling of your aspects (attributes) to something like log4net (in the logging example).

Finally, I will need to continue to evaluate performance to determine if it’s a fair tradeoff with increased maintainability of code. I am most concerned on the compact framework side of things, as the processing power that those apps run on is not as great as their desktop counterparts. This is not a knock on PostSharp, but just something to be aware of.

Wednesday, August 13, 2008 3:36:47 PM UTC  #    Comments [0] - Trackback
Programming
 Saturday, August 09, 2008

I spent the last day and a half trying to figure out why a query using FOR XML AUTO was returning the wrong result set. Some background is in order. I’m migrating a database from SQL 2000 to SQL 2005, as well as running the same database created from scripts on SQL 2005 but in a different environment. Both databases contain the exact same SQL in the stored procedure that was the source of the problem, but they were returning different result sets. I even restored the database that worked to the server that had the non-working database and saw that the database created from scripts was still working as expected.

I figured there was a database level setting causing the issue, so I opened up the database properties for both databases and compared them side by side, except I missed the 3 drop down boxes at the top, specifically the compatibility mode. I finally decided to run the SQL 2005 Update Advisor, which comes on the install media, or available online as a download. After about 10 minutes of checking my database (it was across a remote connection), it found the exact problem I was having, and the fix was to get rid of my derived tables, or set the comparability mode to 90.

From the Upgrade Advisor help, here is an example of my original problem.

Consider the following table:

CREATE TABLE Test(id int);
INSERT INTO Test VALUES(1);
INSERT INTO Test VALUES(2);
Now run this query, which produces different results under different compatibility levels.
SELECT * FROM 
   (SELECT a.id AS a, b.id AS b 
    FROM Test a JOIN Test b ON a.id=b.id)
AS DerivedTest 
FOR XML AUTO;

 

Under Compatibility Level 80 you get:

<a a="1"><b b="1"/></a><a a="2"><b b="2"/></a>

Under Compatibility Level 90 you get:

<DerivedTest a="1" b="1"/><DerivedTest a="2" b="2"/>

The XML under Level 90 is what I was looking for. Remmeber, under SQL 2000, the same query worked fine, it was only under SQL 2005 with Level 80 that I started having problems.

Of course after switching to level 90 I found another bug, and wouldn’t you know it, the compatibility wizard told me about this one as well, I just felt like ignoring it at first. This time it was a problem with a table prefix in an order by clause. Funny thing is, the table prefix didn’t even exist in the stored procedure, but under SQL 2000 it worked fine. Turns out someone else had already fixed the issue in the SQL 2005 version.

While looking for the stored procedure in error (since at first I ignored the warning in the upgrade advisor which even told me what stored procedure), I found a quick way to search stored procedures and functions in SQL 2005.

SELECT ROUTINE_NAME, ROUTINE_DEFINITION 
    FROM INFORMATION_SCHEMA.ROUTINES 
    WHERE ROUTINE_DEFINITION LIKE '%SearchString%' 

Lesson of the day, try using and paying attention to the tools that Microsoft gives you.

Saturday, August 09, 2008 9:13:25 PM UTC  #    Comments [0] - Trackback
Sql
 Tuesday, July 29, 2008

Late last year I posted briefly on the SQL Publishing Wizard. I haven’t had a need for this since I reformatted and installed Server 2008 64 bit as my main workstation at work, and wouldn’t you know it, it’s not there now.

As usual I headed off to Google and found some posts that pointed to this install path, C:\Program Files\Microsoft SQL Server\90\Tools\Publishing\1.2. Seeing as I am running a 64 bit Windows OS, my path is actually C:\Program Files (x86)\Microsoft SQL Server\90\Tools\Publishing\1.2. Now you could just run SqlPubWiz.exe, or run the VSInt.reg file to add the context menu option in Visual Studio 2008.

Not so fast, the registry file doesn’t seem to work as is on a 74 bit OS due to the new subkey, Wow6432Node. I modified VSInet.reg to include the keys the Wow6432node, and in the end got my Publish to Provider context menu option back.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VWDExpress\9.0\Menus]
"{40d75537-ce10-4311-a7b0-6b164d80405d}"=",1000,1"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Menus]
"{40d75537-ce10-4311-a7b0-6b164d80405d}"=",1000,1"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VWDExpress\9.0\Menus]
"{40d75537-ce10-4311-a7b0-6b164d80405d}"=",1000,1"
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\Menus]
"{40d75537-ce10-4311-a7b0-6b164d80405d}"=",1000,1"

 
Tuesday, July 29, 2008 4:10:48 PM UTC  #    Comments [0] - Trackback
Sql | Tools
 Saturday, July 19, 2008

Just found a blog post by the Microsoft SQL Server Development Customer Advisory Team  entitled How can SQL Server 2005 help me evaluate and manage indexes?. This post goes over 5 ways to analyze your index usage in SQL 2005. There looks to be some good technical information on this blog, worthy of any DBA in training.

Saturday, July 19, 2008 11:48:03 PM UTC  #    Comments [0] - Trackback
Review For Future Projects | Sql

My domain controllers, and thus my member servers and workstations were having some serious time drift. I’ve seen +/- 30 minutes this week so far. I found a good article from Microsoft on how to enable a computer (including domain controllers) to sync to an external time source (http://support.microsoft.com/kb/816042). I’m running two instances of Server 2008 server core, so I used the remote registry functionality to set the registry keys for w32time and restarted. I’m syncing to north-america.pool.ntp.org (don’t forget the ,0x1 at the end of our peer list).

Since my domain controllers are virtual machines, I also setup one of my physical hosts to sync to an external source as a backup.

Saturday, July 19, 2008 2:37:51 AM UTC  #    Comments [0] - Trackback
Technology
 Monday, July 14, 2008

It’s been awhile (4 months) since I last update my HTC mogul from the stock ROM that came with the phone to a cooked ROM and leaked radio ROM. Lately my phone has been acting kind of buggy, with having to reset it every morning to get my data connection back. So I decided it’s time to upgrade to the RTM version of the radio, and a new version of DCD’s ROM.

I will be highlighting the steps I outlined in my last post Cooked ROMs on the HTC Mogul, which seems to get quite a few hits from the search engines. Here are some additional links with good information:

Here are my updated steps for updating my phone

  1. Download all required files
    • DCD Rom 3.2.2 (listed in forums not wiki)
    • Sprint CAB File
    • Olipro 2.4 (I already had this bootloader installed on my phone).
    • Titan Radio ROM 3.42.30 (listed in the forums, not wiki)
  2. Write down your MSID, MSD and AKey settings from ##778#. If you do not know your MSL, you will need to get the SPC program.
  3. Write down data from ##3282
  4. Format your non-SDHC (smaller then 2GB Secure Digital Card) as FAT32. I backed up the contents of my SD card and formatted it clean for this process.
  5. Extract the Titaimg.nbh file from the Sprint Radio Rom rar file and copy to your SD card. The file must be named Titaimg.nbh (notice there is no N, it’s not titaN).
  6. Load the ROM by launching the boot loader using the power+camera+reset combination
    1. Wiki states that the update will stop 5 times for 9 seconds each time, so don’t freak out.
    2. When it says update complete, update success, do a soft reset and the the phone boot. You can verify the Radio version under Device Information in your System Settings page.
  7. Extract the RUU_signed.nbh from DCD’s 3.2.2 executable you downloaded using winrar. Rename this file TITAIMG.nbh and copy to your SD card overwriting the previous .nbh file.
  8. NOTE: You are about to wipe all data from your phone so back up what you need.
  9. Reboot into the boot loader with your SD card loaded.
    1. Soft reset when you see update complete/update success
  10. Complete the touch screen calibration, but perform a soft reset before the customization crap starts.
  11. Run the sprint carrier cab on your device and then reset. This will let you access the ##778# and ##3282# screens. If you can’t use your phone or data connection, access the ## screens and re-enter the data you copied down in step 2

Step 11 thru me for a loop until I remembered I had downloaded that carrier cab and should probably install it. I miss the default gray theme that I had in the last ROM, and it takes awhile to load everything back up on my phone. I hope that my daily reset requirement is no more, or I will be a little disappointed in my time invested in this project.

Monday, July 14, 2008 1:06:51 AM UTC  #    Comments [0] - Trackback
Technology
 Wednesday, July 09, 2008

We have some WSE 2.0 secured Web Services that we are migrating to a new data center. As part of this migration effort I needed to write some automated tests to make sure everything was working. In addition to working with the WSE 2.0 clients our customers have, I also wanted to see what was needed to make the services consumable by WCF clients. After finding this article on WSE 2.0 Interoperability on http://wcf.netfx3.com, it was pretty easy.

The main problem I was having was issues with the username token. In WCF some basic concepts were changed, such the removal of password encryption (instead recurring the transport, https for example to handle encryption), and replay detection.  

Here is the config section from the WSE 2.0 server piece (the diagnostic piece is optional)

<microsoft.web.services2>
   <security>
      <securityTokenManager xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" qname="wsse:UsernameToken">
         <replayDetection enabled="false"/>
      </securityTokenManager>
   </security>
   <diagnostics>
      <trace enabled="true" input="logs\InputTrace.webinfo" output="logs\OutputTrace.webinfo" />
   </diagnostics>
</microsoft.web.services2>

Here is a sample configuration section for the WCF Client:

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="InventorySoap" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="TransportWithMessageCredential">
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://Server/Directory/Service.asmx"
                binding="basicHttpBinding" bindingConfiguration="InventorySoap"
                contract="MonitoringServices.Inventory.Wcf.InventorySoap"
                name="InventorySoap" />
        </client>
    </system.serviceModel>

Most of the client configuration was created for me when I added a service reference to my project. The key part is the mode=TransportWithMessageCredential and clientCredntialType = “UserName”.

We have another project underway were we want to rewrite the WSE 2.0 services with WCF while maintaining full compatibility with deployed WSE 2.0 clients. The netfx3 article covers this scenario as well, and it seems like we will be able to accomplish our task. Look for a future post on that endeavor.

Wednesday, July 09, 2008 4:30:23 PM UTC  #    Comments [0] - Trackback
Programming
Archive
<August 2008>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456
About the author/Disclaimer

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

© Copyright 2009
Adam Salvo
Sign In
Statistics
Total Posts: 176
This Year: 0
This Month: 0
This Week: 0
Comments: 10
Themes
All Content © 2009, Adam Salvo
DasBlog theme 'Business' created by Christoph De Baene (delarou)