Tag Archives: .net

LINQ Distinct Fix

21 Dec

I needed to use the LINQ Distinct operation on a list of objects today and I ran into the fact that Distinct doesn’t take a lambda expression. You have to create a class that inherits IEqualityComparer and implements both the Equals and GetHashCode methods. This seems like a real pain to me. Distinct should take a lambda expression like the rest of the LINQ operators.

I found a workaround by using GroupBy, First, and Select like so.

var distinct = collection
       .GroupBy(c => c.FilterProperty)
       .Select(c => c.First())

ASP.NET Learning Project

17 Nov

Thanks to Ayende Rahien I have run across a very interesting little project that I think would be a good project for anyone looking for an example project to use to learn some solid ASP.NET skills.  The project that is mentioned here is called the Cuyahoga Project. It’s an open source .Net web site framework.

Cuyahoga uses NHibernate as its ORM, implements logging with log4net, and uses the FCKeditor for editing page content.  Cuyahoga is a very nice intermediate ASP.NET project to base a web project off of.  I will certainly keep it in mind the next time I get to start an ASP.NET project from scratch. It seems much simpler to work with than DotNetNuke and since its open source/freeware its much cheaper then Community Server.

What Hung Me Up On Using ASP.NET MVC Preview 4

13 Aug

I was delving into ASP.NET MVC Preview 4 for a small project and I got hung up on form validation.  Currently ASP.NET MVC provides no way to validate form input against the model objects.  Form validation has to be written client side in JavaScript and server side in the action.  I would really like to be able to decorate the LINQ-to-SQL objects fields with validation information like Rails does.  I also hope they add some validator helpers to the the HTML helpers.

I see that someone else ran into this and went ahead and coded a solution for it the Forms Framework with Validation for ASP.NET MVC.  This is an interesting approach to the problem I am not sure how it would deal with forms that are using more than one model.  I want Microsoft to address this feature rather than cobbling basic functionality together from a lot of little side projects that may not see any further progress after their initial development.

ASP.NET MVC Beginner Mistake

24 Jul

My last post was the result of making a beginners mistake and spending a lot of time being unable to resolve the issue.  Since I am using IIS 6 on XP/2003 I have to add .mvc to my controller paths to activate the ASP.NET MVC framework on a URL.  I was doing this and my controllers were working except for the / path of the web site. 

ASP.NET MVC still needs a default.aspx in the root of the web site.  The default.aspx just performs a redirect to the URL of whatever controller you are using for the site root. I had not changed the URL that default.aspx was redirecting to.  Once I changed the URL the redirect was using my problem was fixed.  I want to give a shout out to the official ASP.NET MVC forum for the help I got there.  Its nice to see that a Microsoft product is building an actual community around this technology as that more than anything will help it grow and evolve.

ASP.NET MVC Here Be Dragons

23 Jul

I tried to start a new project using the latest ASP.NET MVC framework update and it didn’t go so well.  I ran into three issues that caused me to go back to the standard ASP.NET stack.

I was trying to redirect from an action on one controller to an action on another controller.  RedirectToRoute wasn’t working for me instead of being redirected the current action just kept being reloaded.  This really irritated me because either this is a bug in the framework or I was being tripped up by a misunderstanding of how asp.net mvc works. 

When I went to the official asp.net mvc forum to see if I could find any documentation on this I found several people complaining about things that worked in preview release 3 that don’t work in release 4. This tells me the framework fundamentals are more in flux than I would feel comfortable dealing with at this time.

In trying to dig up documentation on the asp.net mvc framework there was no central repository of information. I really wish they would centralize the existing documentation and update it with each release.