Entity Framework Tips and Tricks: Use GetObjectByKey When Querying a Single Entity

7. September 2011
I’ve been using Entity Framework a lot lately and it makes data access really nice. It’s fairly simple to use and maps all your tables to a .NET object model. However, just like any other library, it can be misused and have it’s own issues. I’ve been figuring some things out as I’ve been using it, so I thought I’d share a few tip and tricks that I’ve learned. Here’s the first one: Use “GetObjectByKey” when Querying for a Single data entity Take the following query: var person = (from p in con... [More]

C# , , ,

Mixing some Dynamic-ness with IronJS in .NET 4

24. August 2011
I recently started messing around with IronJS again, and I must say that this project is pure awesomeness! One of the first things I noticed is that when you call the “Execute” methods to run some JavaScript code it returns an “object.” Now, while this works just fine, I would prefer if it returned a “dynamic” object while running against .NET 4.0. There may be some reason that Fredrik Holmstrom (the author) decided to return an ‘object’, so I don’t mean to sound negative, but you have to admit ... [More]

JavaScript, C#, DLR , , ,

Odd .NET Namespace Scoping Causes Compile-Time Exception

1. January 2011
This isn’t really a bug in the .NET compilers, but it sure is an interesting namespace scoping issue that could easily be encountered. If this teaches you anything, be it that you should never name a nested namespace level the same name as one of its parents in the hierarchy. In C# First here’s the Compile Time Exception that I was getting: The type or namespace name ‘Data’ does not exist in namespace ‘MyApp.Data.MyApp’ (are you missing an assembly reference?) At first I was like “What do yo... [More]

C#, vb.net , ,

Silverlight: Modify MEF to load plugins from DLL and XAP files

22. October 2010
I’m using MEF in a new project, and the limitation that I’ve found in using MEF with Silverlight is that it only supports downloading and loading plugins/assemblies from XAP files. What I would really like to do is support plugins that are compiled into either individual DLL’s or more complex plugins within a XAP. Update: I have also posted this to the Issue Tracker on the MEF CodePlex site. Why individual DLL’s? The really answer to this is flexibility. I don’t think they creators of MEF mad... [More]

Silverlight, C# ,

Use New Bing Maps Road Imagery In Silverlight Map Control (Unofficially and Unsupported)

19. August 2010
Recently the consumer facing Bing Maps site changed the map imagery that is displayed for the Road map mode. This map imagery has not been officially made available for Bing Maps for Enterprise developers to use within their applications. The imagery is only officially available to the Bing Maps consumer website. Unofficially, you can still access the imagery if you know the URL format to get it. Below is an example of using the URL format for the new imagery to display it within the Bing Maps ... [More]

Bing Maps, C#, Silverlight , ,

Loading Microsoft CDN Hosted OpenStreetMap Imagery in Silverlight Bing Maps Control

19. August 2010
Recently a new Bing Maps App for OpenStreetMap (OSM) was released. This new feature of the Bing Maps consumer facing website is hosting the OpenStreetMap imagery using the Azure CDN, rather than relying on OpenStreetMap’s server. There has been some question as to whether developers can use the Microsoft hosted OpenStreetMap imagery within their own applications. I have not seen anything official from Microsoft on this, so I assume that doing this is against their terms of use. You assum... [More]

Bing Maps, C#, Silverlight , ,

Prototype of OpenStreetMap Silverlight Control using DeepEarth and Bing Maps SDK

13. November 2009
I’ve decided to expand a little on using OpenStreetMap imagery with the new Bing Maps Silverlight Control in response to the following comment posted by John O’Brien on my previous “Display OpenStreetMap Imagery using Bing Maps Silverlight Control v1” post: “Very close Chris but you will still need to enter a Bing Maps AppID. If however you create your own map from MapCore and don't use the Bing Maps services then you don't need creditials” Yes, it is t... [More]

Bing Maps, C#, Silverlight , , , ,

Getting Started with Bing Maps Silverlight Control v1.0

12. November 2009
It’s been 8 months since the CTP release of the Bing Maps Silverlight Control at MIX’08, and finally this week Microsoft released the Final v1.0 release of the control to the web.  Now, we can all finally start using the Bing Maps Silverlight Control in Production! If you’ve worked with the CTP, then you’ll want to take a look at Ricky’s “Migrating from Bing Maps Silverlight CTP to Production Version” article. It explains all the stuff you’ll... [More]

Bing Maps, C#, Silverlight , , ,

Virtual Router Project – Turn any Windows 7 PC into a Wireless Access Point / Hot Spot

9. November 2009
Over the last week some of you may have heard about Connectify. It’s an app that unleashes the “Virtual WiFi” and Wireless Hosted Network features of Windows 7 to turn a PC into a Wireless Access Point or Hot Spot. Well, I looked into what it would take to build such an app, and it really wasn’t that difficult since Windows 7 has all the API’s built in to do it. After some time of looking things up and referencing the “Wireless Hosted Network” C++ sample... [More]

C# , ,

Resolve IP Address And Host Name From MAC Address using C# and Windows ARP Utility

8. November 2009
While working on the Virtual Router project, I’ve come across a need to be able to retrieve the IP Address and Host Name of a given machine on the local network when only the machines MAC Address is known. This took a bit of research to figure out, and eventually I stumbled across the “arp.exe” utility within Windows. “arp.exe” uses the Address Resolution Protocol to provide functionality to add, delete or display the IP address for MAC (Media Access Control) address translation. To see the IP... [More]

C# , ,

.NET Windows Service Installer and Auto Start After Installation

6. November 2009
It’s not very often that I need to build a Windows Service for a specific task, and it’s even more rare that I need to create an Installer (.msi) to install/uninstall the service. Well, the project I’m currently working on (http://virtualrouter.codeplex.com) requires me to 1) Install a Windows Service using a Setup Project, and 2) Start the Windows Service immediately after installation. Create Setup Project for Windows Service Just create a Setup Project within your Solution in Visual Studio,... [More]

C# , , ,

A Couple VB.NET Language Tips for C# Developers

31. October 2008
Originally, I started out as a Visual Basic developer, and have since moved mostly to C#. However, when doing consulting work, I do need to cross back and forth quite often. Here are a couple VB.NET tips that you probably aren't aware of if you're mostly a C# developer. Some VB.NET developers may not even know about then either. Null Coalesce Null Coalescing is really simple in C#: [code:c#] // If "someValue" is Null then set "i" to 0 (zero) // otherwise set it to the value of "someValue" in... [More]

C#, vb.net , ,

C#: Generate WebPage Thumbmail Screenshot Image

23. July 2008
There are a few services out there that serve up screenshots of any webpage for you to display on your website. One popular one is Kwiboo; this is the one that DotNetKicks uses. For some time now I've wondered what the easiest way to do this in .NET was, and today I stumbled upon the undocumented WebBrowser.DrawToBitmap method that makes this extremely easy to do. By the way, I stumbled upon the WebBrowser.DrawToBitmap while taking a look at the source code for the WebPreview tool over at Small... [More]

asp.net, C# ,

C#: Enhance Enums using Extension Methods

15. July 2008
Extension Methods are one of the coolest features that have been added in .NET 3.5. I've heard arguments that there is no reason to use them, and the only reason Microsoft added them is to enable the ability to buid LINQ. Well, I do not entirely agree with that statement; in fact, I have found a cool way to use Extension Methods to enhance the System.Enum object since it cannot be inherited. Even though Enum can not be inherited, it can be extended using Extension Methods. [More]

C# ,

.NET: Why aren't Private Abstract methods allowed?

26. February 2008
Sometimes when creating base objects you want to create methods that are overridable by object that inherit the base object, but keep the methods from being public. However, the compiler throws an exceptions when you try to define a method as "Private Abstract". Why doesn't the compiler like "Private Abstract" methods? The reason for this is Private methods can not be overriden. So, essentially the Abstract is useless if the method is Private. How can I create a "Private" method that's a... [More]

C#, vb.net ,

Search Keyword Highlighter BlogEngine.NET v1.3 Extension

13. February 2008
In my previous blog, I used the se_hilite.js file from Scott Yang to hightlight the search keywords people used to search for my site when they are referred to my site via the search engines. This is functionality that I want to maintain, and I couldn't find an existing extension. So, I decided to write one. This is a really simple extension, and a neat feature to have. Here it is... [More]

C#

Calculate Distance Between Geocodes in C# and JavaScript

1. February 2008
There are times when I need code to calculate the distance between two geocodes (Lat/Long points). I don't need it very often and until now I didn't have a code snippet that I could jus copy and paste. I was searching and found Rob Conery's LINQ and Geocoding post. It's an interesting post and he includes a sample of how to use Lambda expressions in C# 3.0 to calculate the distance between two geocodes in Miles. I decided to copy his code snippet and make sure it works in .NET 2.0 and also conv... [More]

C#, JavaScript , , , ,

2008 Microsoft Launch Event and Free Software

21. January 2008
On February 27th in Los Angeles, CA, Microsoft is kicking off a series of "HEROES happen {here}" launch events nationwide. These are the official launch events for Windows Server 2008, Visual Studio 2008, and SQL Server 2008. And, one of the best parts is everyone that takes part in one of the events will be taking home a promotional kit with versions of all three products. Since the Milwaukee event isn't until May 8th, I've registered for the Chicago event on March 11th. I don't want to w... [More]

C#, vb.net

.NET: How to Alias Namespaces and Data Types

26. November 2007
One of the little known features of .NET is that you can give complete namespaces and data types alias's that you can reference them with in code. Aliasing Data Types For this example we'll give a different name to the integer data type: In VB.NET: Imports MyInteger = System.Int32; In C#: using MyInteger = System.Int32; Now to use the alias in code: In VB.NET: Public myVariable As MyInteger = 4; In C#: MyInteger myVariable = 4; Aliasing Namespaces For this example, lets assume ... [More]

C#, vb.net

Microsoft to release .NET Framework 3.5 as Shared Source!

3. October 2007
Scott Guthrie announced on his blog today, that Microsoft will be releasing the source code for .NET 3.5 as shared source under the Microsoft Reference License (MS-RL). You will also be able to enable debugging support within Visual Studio 2008 for the .NET Framework. This is really cool. I have always used .NET Reflector to peek into the source of the framework, but now I'll actually be able to look at the code itself. More Info:Releasing the Source Code for the .NET Framework Libraries ... [More]

asp.net, C#, vb.net , ,

Parallel FX Library: Optimize your code for Multi-Core machines

12. September 2007
I was reading the October 2007 edition of MSDN Magazine and came across an article titled "Parallel Performance: Optimize Managed Code For Multi-Core Machines." At first I thought that this was just another article explaining how to use the ThreadPool in .NET to improve the performance of you app, but they are actually talking about the new Parallel FX Library that is about to reach its first CTP. What is this Parallel FX Library? Simple... It's a .NET library that is designed to make is much ... [More]

C#, vb.net

Creating an IDE? Use the Visual Studio 2008 shell as your base.

15. July 2007
Starting with Visual Studio 2008, you'll be able to use the Visual Studio 2008 Shell as the starting point to create your own development tools. The Visual Studio Shell will be available as part of the Visual Studio 2008 SDK, but I believe we'll have to wait until VS'08 RTM's before we'll be able to play with creating apps using the shell. On the Visual Studio 2008 Shell page, there's a screenshot of Floorplan designer built using the VS'08 Shell. This looks like a really neat feature that... [More]

C#, vb.net ,

.NET 3.5: How to Convert from one TimeZone to another

23. June 2007
The ability to convert directly from one timezone to another is coming (finally!) in .NET 3.5 via the addition of the System.TimeZoneInfo object. Example C# Code:DateTime oldTime = new DateTime(2007, 6, 23, 10, 0, 0);TimeZoneInfo timeZone1 = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");TimeZoneInfo timeZone2 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");DateTime newTime = TimeZoneInfo.ConvertTime(oldTime, timeZone1, timeZone2);

C#, C# ,

C#/VB.NET: Extension Methods

13. March 2007
Over a year ago I posted a question about doing a SQL-like IN operation in .NET. Here's the examples I posted of how it could work: Dim arrNames() AS String = New Array{"CHRIS", "TOM", "TYLER"} If strName IN arrNames Then    'do something End If Now, this would be a powerful feature since you wouldn't be required to write code that loops through the array or collection. Well, I saw some good news today posted by Scott Guthrie. ... [More]

General, vb.net, C#

Visual Studio 2005 Add-In: Get the total number of line of code in your solution

11. October 2006
Here's a Visual Studio 2005 Add-In that shows you the total lines of code within your solution/project. It also show the breakout of each individual file. Currently it doesn't include line counts from files within any WebSites that are included inside your solution. But overall this Addin is simple and to the point. Besides, it's open source so you can fix/modify it in any way you'd like. Visual Studio 2005 Line Counter Add-In + Source Code 

C#, vb.net ,