Thoughts from Dan Miser RSS 2.0
 Friday, September 23, 2005
As I mentioned in my previous post about LINQ and IDENTITY fields, I was getting an exception when trying to update back to the DB. I have since tracked this down to my guess in that post where it was due to the way that I constructed the customer object via foreach. Using that technique, it seems that it keeps a DataReader open longer than needed, which results in this error. I have a workaround, so I can at least share this sample to show you how related tables with IDENTITY fields work. If you want to see the exception, replace the line where I assign the cust variable with a "foreach (var cust in query)".

Things to note in this sample:

  • I am mixing and matching objects retrieved from the DB (cust) and locally created objects (o and od).
  • You can assign the Order object to the customer either by setting o.Customer to point to the customer, or using cust.Orders.Add(o). The same holds true for adding OrderDetail to Order.
  • IDENTITY fields are not initialized upon creation, but they are assigned the actual value that they got when getting inserted to the DB.
  • You can link tables together by either using the object references or the actual data field. For example, when building the OrderDetail object, I use od.ProductID to set the value that will get written to the DB. I could also have constructed/received a Product object from the DB and assigned od.Product to do the linking via object reference.
  • Linking between related tables is taken care of automatically, even when linked via IDENTITY fields


    class Program
    {
        static void Main(string[] args)
        {
            Northwind db = new Northwind(
                @"Data Source=(local);Initial Catalog=Northwind;Integrated Security=True");
            db.Log = Console.Out;

            var query = from c in db.Customers
                        where c.CustomerID == "ALFKI"
                        select c;

            Customer cust = query.ToArray()[0];
            Order o = new Order();
            o.Customer = cust;
            o.Freight = 23;
            Console.WriteLine("[PRE] Order.OrderID == " + o.OrderID);

            OrderDetail od = new OrderDetail();
            od.Order = o;
            od.Quantity = 1;
            od.ProductID = 1;
            Console.WriteLine("[PRE] OrderDetail.OrderID == " + od.OrderID);

            //o.OrderDetails.Add(od);
            //cust.Orders.Add(o);

            db.SubmitChanges();
            Console.WriteLine("[POST] Order.OrderID == " + o.OrderID);
            Console.WriteLine("[POST] OrderDetail.OrderID == " + od.OrderID);
        }
    }
Friday, September 23, 2005 12:54:00 PM (Central Standard Time, UTC-06:00)  #    Comments [0] -
LINQ
I was preparing a writeup on how LINQ handles IDENTITY fields, and there is some mixed news on this front. First off, the good news. The concept of how LINQ will deal with IDENTITY fields is quite solid. The goal is to have the DB return the new value for the IDENTITY field and then populate the object with that new value. Very slick. Back in Delphi 5, MIDAS introduced a property TDatasetProvider.ProviderOptions.poAutoRefresh that was supposed to do this same thing. However, it was never implemented, so it never worked. As a result, you had to use other options, like the one I outlined in my BDN article. So LINQ has a definite advantage here.

The other really cool things about LINQ IDENTITY handling is that you can build up a graph of objects (i.e. Orders and OrderDetails), add the object to a Customer object, and when you do a SubmitChanges(), the IDENTITY fields are updated properly throughout the whole object graph, in addition to linking properly in the DB.

However, the bad news is that the DLINQ implementation is throwing a System.InvalidOperationException because "There is already an open DataReader associated with this Command which must be closed first.". If you are debugging the application and pause long enough before continuing, the data will still get written to the DB. However, I have not been able to get the application to work at all when just running it (i.e. Start Without Debugging). I believe it may be due to my mixed use of retrieving a customer from the DB using LINQ, and then creating Order and OrderDetail objects locally and adding them to the Customer object. I say this because doing a simple add of a Category object all by itself doesn't yield this exception. I also had an instance one time where only the Order was inserted, and not the OrderDetail, thereby invalidating the atomicity of the transaction. I plan on cleaning up the test case and submitting it to MS. Anyone know where this kind of feedback should go?

Friday, September 23, 2005 10:58:00 AM (Central Standard Time, UTC-06:00)  #    Comments [4] -
Delphi
 Sunday, September 18, 2005
In the current version of DLINQ, you can only target MSSQL. The architecure seems to be extensible enough to allow for DBMS vendors to provide their own DLINQ assemblies so that when you write DLINQ queries, you will be allowed to communicate to a variety of back-ends. See System.Data.DLinq.Provider.ProviderContext for the class that you can use to descend from in order to get your own DBMS supported. Talking with MS, it appears that they are hoping that each and every vendor will provide their own assemblies. I think this is a mistake for the following reasons:

  • First off, the current code in System.Data.DLinq.DataContext uses code in System.Data.DLinq.SqlClient. It essentially forces the ProviderContext to be SqlClient. This will have to be cleaned up and made more generic before a vendor can deliver something.
  • I believe it's time for MS to start providing tools that allow the developer to mix and match parts. Until MS does this, they will continue to develop solutions that work well with MSSQL, but will miss out on what other DBMSes can do. They need to take the lead by providing other DBMS versions so they can see where the holes in their current approach are. If they wait for the vendors, it will most likely be too late to change the code to do what needs to be done to support 3rd party DBs. It's a Catch-22. DB vendors will wait to write their assemblies until MS cleans up the code (see point 1 above), and see that doing this will yield positive returns. When they finally do this, it may be too late to have the DLINQ architecture changed to accomodate whatever specific hooks may be required to get first-class support of the 3rd party DB.
  • It doesn't appear that there is any registration/management code in place to allow for you to simply say: "I'd like to use MSSQL (or Oracle, or InterBase)". It seems that this would be resolved by which assemblies you reference in your code. But how well will this work when you want to target multiple DBs in your application?
  • Finally, the competition (i.e. Borland) already provides low-level multi-DB code in several cases, and has for years: BDE, DBExpress, and Borland Data Providers (BDP). If a company with a development team that is a minute fraction of MS's development team can deliver this, there's no reason MS couldn't do the same.
Sunday, September 18, 2005 9:14:00 PM (Central Standard Time, UTC-06:00)  #    Comments [5] -
LINQ
 Friday, September 16, 2005
There is some conflicting information out there about what you need to run LINQ. This link says that the C# LINQ Tech Preview will only work with VS.NET 2005 Release Candidate (RC). What is troubling is when you download the MSI file from that page, it is the same exact MSI file as the one distributed on Disc 4 at PDC. That file would only install on VS.NET 2005 Beta 2.

To make matters worse, this link tells us that the VB LINQ Tech Preview from the web site will only work with VS.NET 2005 RC (as does The LINQ Project Page). If you install RC and then the VB LINQ Tech Preview, you'll find that the files that get installed are newer than the C# version. However, the VB package is missing the System.Data.DLinq assembly.

I imagine updates will be coming to sort all of this out soon, but just thought you should be aware of the current state of things. To make things simple for now, use Beta 2 and C#.

Edited on 9/17 to add: Looks like MS updated the page to say that C# only works with Beta 2.

Friday, September 16, 2005 10:13:00 PM (Central Standard Time, UTC-06:00)  #    Comments [1] -
LINQ
.NET Language Integrated Query (LINQ) is here. We've seen a couple of teasers over the past few months, but after seeing this stuff in-depth for a few days, I have to admit that I love what I see. So much so, that I created a new feed for it because I plan on writing about LINQ quite a bit. For now, the generic description will have to do. It's a way to write query-like statements that can operate on sets, XML, data, and more using one syntax. Furthermore, this is all available in your native programming language (C#, VB, and others will follow soon, I'm sure), which means rich type information at design-time, and it's strongly-typed so you'll see errors at compile time. It's in beta right now, and there are all sorts of known warts, but the promise of a useful and valuable tool is excellent.

Stay tuned for more information on LINQ!

Friday, September 16, 2005 7:05:00 PM (Central Standard Time, UTC-06:00)  #    Comments [0] -
LINQ
 Sunday, September 11, 2005
Microsoft emailed me to tell me that they're giving away a copy of OneNote to PDC attendees. I installed it to play around with it, and it seems to be quite a useful application. OneNote allows you to take free-form notes, works on TabletPC, integrates with Outlook, is shareable between team members, allows external document linking, allows you to insert video or audio, is fully configurable based on your categorization scheme, has a bunch of pre-defined templates and is searchable (and I'm sure plenty of other features that I haven't discovered yet). I don't know about you, but I have todo.txt files laying all over my hard drive. I put all of them into OneNote, and it seems to me that this makes more sense. I'll be giving OneNote a chance here, and I look forward to bundling all of my PDC notes into it to see how it will work out.
Sunday, September 11, 2005 1:09:00 PM (Central Standard Time, UTC-06:00)  #    Comments [1] -

 Saturday, September 10, 2005
I'll be heading for Los Angeles on Monday to attend PDC '05. I'm pretty excited about going. I have at least 3 sessions I want to attend in almost every time slot. I will definitely need to find a way to filter the most important sessions to the top.

I doubt that I'll be doing any real-time blogging on the event, but I found this link that should keep you in the loop if you don't make it there.

Saturday, September 10, 2005 2:21:00 PM (Central Standard Time, UTC-06:00)  #    Comments [1] -

Make the time to go and watch the video of JBuilder 2006 Virtual Peer Programming. In one word: Brilliant! In many words: Absolutely drop-dead awesome, incredible, fantastic, and many other synonyms for great. :-)

In a nutshell, JB2006 will allow you to carry on IM conversations; share projects among multiple team members; cooperatively and synchronously view, navigate, edit and debug shared projects. The concept is great, and the implementation is even better. I can't wait to get my hands on this in a future version of Delphi! Imagine, no more requests like "This isn't working, can you stop over?". The possibilities are almost endless. To name a couple of the top of my head, interactive training/mentoring without taking a flight to the client's site and using this to implement XP anywhere.

For some background, I remember chatting with Pat Kerpan back when I was in the DSP group at Borland. The conversation revolved around this very idea, and how it could help with product development. As a matter of fact, I actually wrote Delphi and JBuilder plugins to integrate TeamSource DSP into the IDEs. Among the many features those plugins had, one of them was an integrated IM client (implemented via Jabber). It was actually quite handy to have in your IDE. At first, I wasn't sure how useful it would be, but I soon became very dependent on it. Others seemed to like it to, since it won the Best Team Development Tool award at the 2002 JavaOne conference. Since it beat out Oracle, IBM, and Rational, I was quite proud of my contribution.

Still, it's a strange feeling to view this video. It's not like I'm seeing my baby being born, but more like watching from afar as my best friend has a baby that I've always wanted. Yeah, I know. Quit with the metaphors while I'm behind. ;-)

Saturday, September 10, 2005 1:44:00 PM (Central Standard Time, UTC-06:00)  #    Comments [3] -
Delphi
 Sunday, September 04, 2005
In the spirit of the old "touch" application, which allowed you a command line interface to set the date/time stamp of the file to a specific value, I am now releasing "bump". It's a utility that allows you to set version information on files. Some may argue that this isn't a good idea, but you could make the same argument for countless other utilities, too. Besides, you can already do this by jumping through more hoops if you use a resource editor. Basically, if you know what you're doing, and you need this functionality, now you have it. In the initial release, you can get help on the syntax by just typing the command "bump". The syntax for a bump command looks like this:


bump filename.exe

This will increment the build portion of the file version information for that file by 1. If you don't have versioin information for that file, it won't work. However, you can also use this syntax to either create version information, or set existing version information to a specific value:


bump filename.exe 1.2.3.4

The version string requires all 4 values to be set (major, minor, release, and build).

I'd like to thank Colin Wilson, since I used some of his code to create this utility. I sent my changes back on to him, so hopefully, he'll find those useful.

My wishlist of features coming up for this utility (some are already started, or in various states of undone):

  • Support RES files
  • Allow for a "touch" option to be integrated into this utility
  • Allow for batch file processing
  • Allow for string values to be passed into this utility
  • Finish the GUI version
  • Finish the COM version
  • Finish the FinalBuilder version (I am currently using the console version inside FB within a List Iterator and it works awesome!)

Leave a comment here if you find it useful.

Sunday, September 04, 2005 9:40:00 PM (Central Standard Time, UTC-06:00)  #    Comments [7] -

 Friday, September 02, 2005
With the loss of Project | Web Deployment Options in Delphi 2005, you will need to create your HTML files by hand to display ActiveForms. When doing this, remember that you will need to specify the GUID of the CoClass, and not the GUID of the Library.
Friday, September 02, 2005 10:24:00 AM (Central Standard Time, UTC-06:00)  #    Comments [2] -
Delphi
 Monday, August 29, 2005
I came across Application Debugging in a Production Environment today, and gave it a quick read. Nicely done. Many times, I am asked "Will you debug this for me?", or hear its cousin "I don't know how to debug". This tutorial should get anyone up to speed fairly quickly. It covers 3rd party tools (e.g. SysInternals) and things like WinDbg - tools that I use on a daily basis to find out what's going wrong. With any luck, I'll hear less of the afforementioned phrases, and more questions like "How can we improve the design of this application". I know, I know. Dare to dream...
Monday, August 29, 2005 5:34:00 PM (Central Standard Time, UTC-06:00)  #    Comments [0] -

Navigation
Archive
<September 2005>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678
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 2008
Dan Miser
Sign In
Statistics
Total Posts: 305
This Year: 20
This Month: 1
This Week: 0
Comments: 601
All Content © 2008, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)