Lance's Whiteboard

Random scribbling about C#, ASP.NET, Sql Reporting, etc.

News

BlogMailr Enabled




Sponsored Ad
Sponsored Ad

Blogs I Read

Developer Sites

Googling, etc...

MSDN Resources

Tutorials & Reference

FW: Batch Updates and Deletes with LINQ to SQL

I'm currently on a project creating a proprietary data-migration tool using C# & Linq.  I'm still new to Linq, but quickly discovered the challenges of doing mass-updates and deletes with Linq.

Specifically, by default Linq to Sql generates a sql statement for each row you are updating.  There is no built-in way to do large batch-updates or deletes without dropping to custom SQL.  After a quick search, I found this great article and sample code by Terry Aney on Batch Updates and Deletes with LINQ to SQL.

It offers solutions to many of the basic problems with some elegant extension methods so you can do things like:

   1:  be_Posts.UpdateBatch( first10, new { Author = "Chris Cavanagh" } );
   2:   
   3:  and 
   4:   
   5:  var posts = from p in be_Posts select p;   
   6:   
   7:  be_Posts.UpdateBatch( posts, p => new be_Posts { DateModified = p.DateCreated, 
   8:                                                   Author = "Chris Cavanagh" } );

Cool stuff!

Posted: Jun 23 2008, 06:07 PM by CodeSniper | with no comments
Filed under: , ,
Minimum & Maximum Dates in code

When updating Sql columns that need a minimum or maximum date, consider using the defaults from the System.Data.SqlType namespace:

   1:  DateTime minDate = SqlDateTime.MinValue.Value
   2:   
   3:  // and
   4:   
   5:  DateTime maxDate = SqlDateTime.MaxValue.Value

This can be a lot safer than putting hard-coded "magic date" constants in your code.

What we dont know "will" hurt us...

I like this article by Nathan Henkel, its essentially about assessing risk and scope of projects and strikes me as a simple truth about the uncertainties you encounter in every project:

Information about any project can be divided into four categories:

1. Things we know (and know we know)
2. Things we know we don't know
3. Things we think we know, but don't (i.e. things we're wrong about)
4. Things we don't know we don't know

Obviously, if you were to try to actually figure out where everything falls, you would put everything into 1 or 2. Everything that should be in 3, you would put in 1 (you're not going to have known mistakes in your information), and everything that should be in 4 would simply be missing.


However, without dealing with specific items, I do think that it's possible to guess at how much "stuff" goes in each category. You can take into account your history ("I tend to often be mistaken about X"), or a general feeling of ignorance ("I've never used framework Y before") to guess how much goes in each category.

http://simplyagile.blogspot.com/2007/10/classifying-information-or-what-we-know.html

Sometimes, I think we get so wrapped up with what we “know” about a project that we fail to quantify what we don’t know, or the degree of certainty to which we actually know what we think we know.  As with solving any problem, the first step is to find a way to quantify and measure uncertainty and risk in order to minimize it. 

If you track this measurement over time, it should also help your estimation and planning on future projects.

Good stuff!

Argotic Syndication Framework 2008 released

I got an email yesterday that a major update to the Argotic Syndication Framework was released.   I have used the older versions of this framework several times for projects that need basic RSS & Atom parsing/generating so I'm looking forward to digging-in to the new release.

If you are not familiar with it, here is a quick blurb:

The Argotic Syndication Framework is a Microsoft .NET class library framework that enables developers to easily consume and/or generate syndicated content from within their own applications. The framework makes the reading and writing syndicated content in common formats such as RSS, Atom, OPML, APML, BlogML, and RSD very easy while still remaining extensible enough to support common/custom extensions to the syndication publishing formats. The framework includes out-of-the-box implementations of 19 of the most commonly used syndication extensions, network clients for sending and receiving peer-to-peer notification protocol messages; as well as HTTP handlers and controls that provide rich syndication functionality to ASP.NET developers.

To learn more about the capabilities of this powerful and extensible .NET web content syndication framework and download the latest release, visit the project web site at http://www.codeplex.com/argotic.

Also, here are some of the new features in this release:

a) Targeting of both the .NET 2.0 and .NET 3.5 platforms

b) Implementation of the APML 0.6 specification

c) Implementation of the BlogML 2.0 specification

d) Native support of the Microsoft FeedSync 1.0 syndication extension

e) Simplified programming API and better online/offline examples

Brian has done an amazing job on this project from the start.  I had intended (and still hope) to jump in and contribute some of my own work, so its great to see how far it has evolved from its first releases.

If you work with RSS, ATOM, or any other syndication format/protocol, you should definitely take a look at this framework for your next project.

I love ClearContext!!

After several months of using the Free version of the ClearContext addon for Microsoft Outlook, I just cant imagine what I would do without it.  It has reduced my email time, kept me more organized, and uncluttered my Inbox better & faster than any ad-hoc system I have devised in the past.

As a developer, I hate it when I have to "code in Outlook".  If it were up to me, I would ban all email during a project and deal with all communication via instant messenging, Scrum meetings, and whiteboards, but the truth is that email is a neccessary evil especially as a Tech Lead who needs to interface with the Project Manager, Customer, and IT personnel.

Enter ClearContext Information Management System...

First, I set it up to flag emails from my bosses in Red, so I dont miss them.  Plus, for good measure, I have an Outlook rule that sets a FollowUp flag to make sure I dont overlook them.  Also, ClearContext automagically ranks emails based upon my prior history with this person, so I know what to do when I get some nice blue and green colored mail too.

If I receive an email relating to my current project, I simply hit ALT-P to popup the CC dialog and flag it with the topic "projects/MyProject" then either leave it in the inbox for further review, or hit ALT-M to file the message for future reference.    Accordingly, if I receive some corporate or administrative relating email, then I assign it's topic appropriately and file the message to send it to its respective holding area.  

The act of assigning a Topic (ALT-P), automatically creates subfolders within my Inbox (e.g.  inbox/projects/MyProject) matching the topic name (Note the trick of adding a "/" to the topic name to create a nested subfolder at the same time).  The act of filing a message (ALT-M), moves it to the subfolder identified by the topic name.  This is great because the messages are nolonger visible in the Inbox listing, but are still within the Inbox via the subfolder.

At that point, my AutoArchive settings will take care of moving it off on a monthly basis in case I need it later.

At some point, I want to look at the full product, which has features for deferring emails, converting them to tasks & appointments, assigning them to other people, etc.   See their section for more on these areas.

If these features are nearly as useful as the ones I use now, then I could *gasp* become even more productive!  woot!

Degrees of optimism in projects

Whenever I lead a project, I always try to plan in such a way that sets me and my team up for success.   I do this in many ways, starting with a good methodology, doing thorough analysis, and providing a level of risk/certainty along with any estimates I provide. 

Part of this strategy involves ensuring that client expectations match developer and project expectations.  I tend to use the tried and true approach; "Plan for the worst, hope for the best".

Some people see me as a pessimist, but I beg to differ - I consider myself a cynical, yet optimistic, realist.  By that, I mean that although I do plan everything based upon the worst case scenario, in my heart I truly believe we are going to achieve the best case scenario every time.  It often surprises me when people take my approach to be negative while at the same time, I often see their approach naive & overly optimistic.

The truth is that there seems to be a gradient scale of attitudes and philosophies employed from project to project depending upon the people leading and participating in the project.

Over the years, I started a private game in my head of creating nicknames for the different patterns of behavior.  Here are a few names of I have toyed with in the past:


"Expect the worst, then add 20%" - The Pessimist

"Expect the worst, hope for the best" - Reformed Pessimist

"Expect the best" - Mr. Optimist

"Expect the best, but prepare for the worst" - Fallen Optimist

"Plan for the worst, hope for the best, but expect something in between" - Uncle Realist

"Just do it!" - El Toro

"It is what it is." - Aunt Apathy

"I don't want to hear about risks, just tell me when it's done." - The Ostrich

"Oh, you arent done yet?" - Captain Oblivious

"How much longer?" - The Waiter

 

Which one are you?  Is there one philosophy or attitude you believe works better than others?

Manual CRUD operations with the Telerik RadGrid control

I have been working on a project lately that was already using the Telerik ASP.NET Rad Controls suite.  One of the new features was a fully editable web-grid, so I chose to use the existing ajax-enabled RadGrid control to speed my development.  I chose to use a 3rd party control, mostly due to time constraints since the project required a grid with inline-editing, full CRUD operations, plus custom column templates, all with heavy Ajax support to avoid postbacks and excessive page size.

I soon discovered, the Telerik controls are nice tool for simple uses where you can use asp.net DataSource controls and automatic databinding, but not so much if you need to get "fancy" with your implementation.  In my case I needed to do 2 things that cross over into the grey area where these controls excel.

First, I'm using an early 2.0 version of NetTiers for the DAL (with Service Layer implementation) with custom mods to the entities as the datasource,  and second, I'm doing some aggregate custom ItemTemplates that require custom data-binding.

This lead to extreme complexity in the implementation because, A) this version of NetTiers' had problems with properly generating CRUD operations for its EntityDataSource controls (NetTiers entities mapped onto a custom ObjectDataSource style control) which prevented me from using the declarative model, and B) the RadGrid control simply sucks if you cannot use automatic databinding and if you require custom databinding logic.

It would be great if I could upgrade NetTiers and/or Teleriki RadControls to the latest versions, but it wasnt possible in this situation, nor is it likely that this would have solved my problems.

Anyhow, all this discussion is basically just to share you this one link to a user-contributed example I found incredibly useful after 3 days of searching their forums, demos, and 3rd party blogs.   This example shows how to manually implement Insert/Update/Delete functionality within the RadGrid control by handling the events OnNeedDataSourceOnItemCommand, OnInsertCommand, OnUpdateCommand, and OnDeleteCommand:

http://www.telerik.com/community/code-library/subm...

The reason this link is important is because the Telerik website, with all of its dozens of examples, consistently shows very basic scenarios, even in samples labeled "advanced".  Also, not all of the API features are fully or well documented to help you figure this out on your own.

Hopefully this simple link (which should be promoted to Telerik's demos/samples page) will help someone else as much as it did me.

Posted: Oct 17 2007, 10:33 AM by CodeSniper | with 3 comment(s)
Filed under:
VPC 2007 Dual Monitor support

I have been trying to find a way to allow you to run Virtual PC 2007 with multiple monitors.  Natively VPC 2007 doesnt support more than 1 monitor, however you can "trick" it by using various techniques that expand the desktop area into a larger virtual desktop.

I tried using the awesome which can extend your screen across separate PC's (think "push" remote desktop), but the new multi-monitor compatibility feature of VPC 2007 (which inexplicably does not add multi-monitor support) made this difficult since it ensures that your desktop recaptures your mouse when you move it outside of the VPC window thus preventing the extended screen from being accessible.

So, instead I tried the Remote Desktop approach mentioned in Steven Harman's blog post.  

Here is a quick rundown on how it works:

Connect 2 monitors to your PC (more than 2 typically don't work with this approach).   Make sure to extend your desktop onto the 2nd screen via Display Properties -> Settings.  Then launch Remote Desktop (mstsc.exe) with the "/span" flag:

mstsc /span

Then just use Remote Desktop as usual by specifying your VPC's computer name in the connection dialog.

When I first tried this, it still didnt work exactly right.  It kept giving me annoying scrollbars instead of going full screen, so I added this extra flag to force it into fullscreen:

mstsc /span /f

Also, since I didnt want VPC to have the extra overhead of maintaining 2 sessions (the console and my new RDP session), I threw in one more flag to make it simply take-over the initial console window:

mstsc /span /f /console

NOTE: The /span flag is only present on the very latest version of Remote Desktop Connection.  Therefore, you must either be running Vista on both PC's, or install the update specified here:

http://support.microsoft.com/kb/925876

There are limitations on how your  monitors must be configured in order for this flag to work.

Also, keep in mind that this technique only enlarges your desktop area sufficiently large enouch to span both monitors, but it DOES NOT behave exactly like the native dual-monitor support you may be accustomed to.  For example, when you maximize a window, it maximizes across BOTH monitors instead of maximizing within the confines of a single monitor.   For now, I'm just dealing with that by avoiding maximizing and just manually resizing windows to fit 1 screen.

 

Advanced Users:

One way to avoid having to arrange windows each time is to use a cryptic, yet incredible tool called Hawkeye ShellInit. ShellInit is a small application that helps you manipulate your desktop & application windows via script.   Here is a small script that will move Visual Studio over the right-hand screen (assuming 1280x1024 resolution) and enlarge it to the correct size.

Position Window, *Microsoft Visual Studio, wndclass_desked_gsk, 1280, 0, 1288, 1002

If you decide to use this tool, make sure and read the readme.txt file for some good sample scripts and ideas.

Link Love: 09/21/2007

I havent been blogging much over the past several months.  The main reason is time, or the lack thereof.  Since I dont have time to write a "proper" blog post, I'm just going to start sharing some link love...

 

Here are a few interesting links I have spent time perusing today:

Posted: Sep 21 2007, 03:47 PM by CodeSniper | with no comments
Filed under: , ,
Note to self: Blog about using Service Broker

Just a note to myself to do a braindump on all this Service Broker shiznit I have been playing with lately.

Potential discussion topics:

  • MessageTypes, Contracts, Queues, and Services.
  • Internal Activation, Routing, & External Activation
  • Using the Sql Server ServiceBroker sample library.
  • Implementation using SqlClr vs. TSQL
  • Developing via messages instead of procedures...
  • Compare & contrast Service Broker vs. Workflow Foundation vs. BizTalk
  • The nifty Sql Service Broker Admin tool (3rd-party)
  • Practical examples:
    • Async "fire-and-forget" stored procedure invocation
    • Query Notification for cache invalidation
    • PubSub
More Posts Next page »