March 2008 Entries

ActiveRecord & the ASP.NET MVC Framework

I have a simple ActiveRecord class: [ActiveRecord] public class Employee {     [PrimaryKey(PrimaryKeyType.GuidComb)]     public Guid? Id { get; set; }       [Property]     public string FirstName { get; set; }         [Property]     public string LastName { get; set; } } I then create a create/edit form on my UI. To update the database is easy with the ASP.NET MVC Framework and ActiveRecord: In my controller: public void Update(Guid? Id) {     var emp = DomainFactory.Get<Employee>(Id);     BindingHelperExtensions.UpdateFrom(emp, Request.Form);     emp.Save();       //Render View } Ok now I want to add a Department Object to the Employee: [BelongsTo(Cascade = CascadeEnum.SaveUpdate)] public Department Department { get; set; } On my form page I create a select dropdown with a list of Departments. The...

ASP.NET MVC Framework Html.Select Gotcha

I have been creating a project that uses the ASP.NET MVC Framework. I am using a select dropdown for the user to be able to select a "Faculty" which is a child object of a "Course". I'm going to use the Html.Select() extension method to do this. So my code goes like this: <%= Html.Select("Faculty", FacultyData, "Title", "Id") %> No problem here, I get my list of Faculties, nice and easy. Right, because I'm know creating the edit page I want this dropdown to have the correct Facility selected when the page loads i.e have a selected value set. The Html.Select takes a fifth property...

NHibernate 2.0 Alpha

NHibernate 2.0 Alpha has been released last night. NHiberbnate is the engine behind ActiveRecord, so I'm looking forward to the new changes (having said that I have been using NHibernate 2.0 from the trunk in production for a while now!)  Check out Ayende's blog for more details.

Silverlight images

Today I have been playing with some Silverlight 2.0 The application that I built was a very simple app, but I still wanted to add some nice imagery to it. So one of my designers created a logo for me to use. Now...I'm a big fan of using PNG's, however it so happens that the designer created a transparent GIF. Fair enough isn't it!? Ok, now to add the image to my canvas in Expression Blend...right click....Insert... wait a minute "Insert" is disabled! ??? I'm confused. Right lets try drag and drop.... no that did not work either. Last try...lets create an Image object...

Holiday?

Right now I'm on holiday for a week, leading up to the Easter weekend. Being on holiday has meant that I have done no C# (or any other kind) of development this week....therefore there as been no interesting bits of work to blog about. So what am I doing on this holiday? well...DIY. "That's not a holiday" I here you say, and you'd be absolutely right. Right now I'm feeling that I'd rather be doing some funky development in Silverlight or find another cool way to use Linq .... Maybe I'll take some time out and do something cool....if I do I'll make...

To var or not to var

If you are using C# 3.0 you may have come across the keyword var. If not you can find information about it here. Basically the var keyword allows you to declare any local variable as type var and the compiler determines the type. For example: string myString = "Hello World"; is the same as: var myString = "Hello World"; (Looks like JavaScript!) But when should we use var? The problem is readability; the more var types you have the less readable it becomes for other to read your code. Sometimes it is also difficult to see what type your variable is; take for example: var myObject...

ActiveRecord & NHibernate.Linq

I've been doing a lot of work with Castle's ActiveRecord. In order to get my data back from the database I have been doing queries like: var activities = Repository.FindAll<Activity>(Expression.Eq("Status", StatusEnum.Published) This works great, except for having to use a string for the property I want to set my expression for. How about this: var mostPopularActivities = Repository.SlicedFindAll<Activity>(new[] { "Categories" }, 0, 5, new[] { new Order("ViewCount", false) }, Expression.Eq("Categories.Id", category.Id), Expression.Eq("Status", StatusEnum.Published)); Anybody understand this? Now it's getting really complex. What we are saying is "Get me all the activities and join categories, and get me rows 0 - 5 (top 5), and...

WP Theme &Icons by N.Design Studio adapted by timheuer and ruined by rodj!