c#
c#
I’ve been conducting interviews over the last couple weeks and have noticed a general lack of understanding regarding Lambda expressions (even in those candidates with senior role titles). So here’s some information about Lamdas that if you don’t already know, you should! First of all, Lambda expressions are just inline methods. Unlike delegates, lambdas have access to variables that are scoped the same as the lambda. So if you have a method with a variable v and a lambda l, the statements inside l will have access to v as in the following example: ...
Thanks to Keith (comment #1 at http://weblogs.asp.net/johnkatsiotis/archive/2010/04/28/huge-ef4-inheritance-bug.aspx#7464062) for that title, btw. After coming from NHibernate, EF4 is an enormous pain to work with. Unlike NHibernate, which basically lets you map any relationship you can dream of, EF4 has a lot of issues with inheritance. Here’s a pretty big one IMO: Take a look at this object hierarchy: Before I continue, if you think we’re working on an edge case I have to disagree. One of the tenets of OOP is the idea of encapsulation – there’s no reason a base class shouldn’t be able...
UPDATE: I’ve cleaned up the code a bit and put it up on CodePlex at http://ordertolist.codeplex.com/ A team member recently wanted LINQ-to-SQL to perform a query with a Contains() clause and return the results in the same order. For example, he was passed a list of People: 1: List<int> idsOfPeopleToDisplay = new List<int> { 578, 291, 788, 230, 45 };
and he wanted to select all People from the database with those IDs, in that order. The following will result in a non-correctly ordered...
LINQ-to-SQL DataContexts have a boolean property called ObjectTracking which is used to determine whether the framework should exert the overhead necessary to remember previous states. This defaults to true and is used to determine the SQL UPDATE command to run when persisting the object. We have a project with data that’s read-only and so we decided to turn ObjectTracking off (set to false). We figured this was a good idea since, the thinking went, it would save overhead and since we’re not persisting the data anyway (read-only) we’ll have nothing to worry about. Boy were we wrong. All...
Mike Gleason Jr has a bit.ly client library written in C# called BitlyDotNet (it’s hosted on here on Google Code). If it wasn’t cool enough before, it just got more awesome. I submitted a new version with the following improvements: Added support for error code 208 ("you have exceeded your hourly rate limit for this method") Overload to shorten multiple URLs in one shot Fixed bug that occurred when hourly limit was exceeded (SingleOrDefault throws InvalidOperationException because of multiple errorCode nodes) This library saved me time on...
It looks like I might be giving a course on Beginning .NET Development to non developers with IT backgrounds. I'm putting together my lectures and it's really hard. I want to make sure that I explain things so others can understand them. Even though this is a .NET course (with a web-based slant), I really see it as a fundamental software development (crash) course. You can’t become a great developer without understanding what’s going on behind the scenes. If you have any thoughts or advice on any of the topics at hand (am I missing a topic? are...
The NY ALT.NET Meetup group met last night and Scott Weinstein delivered a terrific presentation on the Reactive Framework (also known as Rx Framework). If you haven’t heard about it, the Rx Framework is a framework for composing (and consuming) asynchronous events. The way that the framework works is that you subscribe to an IObservable and get notified of new events. Since this is all done async, one of my questions was whether a single subscriber’s consumption of these events is blocking (to itself) or not. That’s probably not the best way to phrase the question, but the code’s...
Take the following XML fragment 1: <?xml version="1.0" encoding="iso-8859-1"?>
2: <con:search-results
3: xmlns:con="http://namespace.contoso.com/business-objects"
4: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5: xsi:noNamespaceSchemaLocation="http://www.contoso.com/dtd/syndication/biz-objects.xsd">
6: <con:search-query>ipod</con:search-query>
7: <con:result-count>2207</con:result-count>
8: <con:start-index>0</con:start-index>
9: ...
UPDATE 02/03/2010: You might NOT want to use this method as it screws up Page Caching: http://blog.statichippo.com/archive/2010/02/03/response.flush-and-the-crimes-against-page-caching.aspx This post is sort of in response to another post of mine entitled Rendering ViewPage to random stream (or not). Back then I was looking for this solution. Now I found it! If you’re not familiar with Response Filters, read the MSDN article and this quick example at aspnetlibrary.com. Basically, Reponse Filters are used to filter output before it gets sent downstream. This is useful if you want to, say, replace certain special characters. Background & the existing Response Filter...
I saw a post entitled Run Async tasks with Fluent Interface written in response to another post entitled Async without the pain. I suppose this post is my response to those posts. While I liked what I saw there, there were some things I wanted to add (like the ability to block until tasks complete), so I wrote my own class along the same lines. There are still some things I’d like to add (like the ability to queue tasks into jobs that run in order), but this works for me right now for what I’m...
Full c# Archive