-
|
I wrote a post about a month ago about using xVal with NHibernate Validator 1.2 which solved a problem I was having upgrading the xVal ‘in-the-box’ provider to work with a newer version of NHibernate Validator . There was a caveat that my solution only worked for ValidatorMode.UseAttribute and I wouldn’t catch XML or Loquacious (or other?) validation. This seemed to work OK, but Fabio Maulo wrote a comment to that post saying NHV has metadata which should be the same no matter which validation mode was used. So I decided to investigate how I could get the metadata without resorting to the NHibernate.Validator.Mappings validationMode specific engines (I was using ReflectionClassMapping, but there are others like XmlClassMapping). I think...
|
-
|
I recently setup my first continuous integration build server using JetBrains’ TeamCity product, and it couldn’t have been much simpler. However I kept running into an issue with my test projects whenever I was using NHibernate or SQLite (very useful or regression tests against an in-memory database). The Problem Everything would run correctly locally using MSTest, but when TeamCity ran the tests I would get the following error: Unable to load type 'NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle' during configuration of proxy factory class. Possible causes are: - The NHibernate.Bytecode provider assembly was not deployed. - The typeName used to initialize the 'proxyfactory.factory_class' property of...
|
-
|
I’ve recently switched from the Enterprise Library Validation Application Block to using NHibernate Validators. If you are not familiar with the NHibernate Validator project, they are part of the NHibernate Contrib project and offer Validation constraints, and validation runner, and tight integration with NHibernate (especially great if you use NHibernate to generate your DB). One of the main reasons for my switch was integration with xVal (which EntLib Validation’s implementation prevents), and also to get some advanced but common validators like Email, Size, NotNullNotEmpty. Anyway, I would recommend that you look at NHibernate Validator if you use NHibernate and are looking for a validation framework. However, this post is about writing...
|
-
|
I’ve been playing with Visual Studio 2010 Beta a little and one of my favorite new features (and there are many) is the new web.config transformation feature. Web.config transformations are setup so there is one configuration “delta” for each build configuration that you have (default are Debug and Release). When you build your solution (as a package, when you publish, etc) your original web.config is transformed according to the settings in your web.debug.config file (assuming the debug configuration). There are plenty of blogs and msdn references out there for you to look at but I thought I’d write a quick post that would get you up to date on how to do the some common web.config transformations. First, A Tiny Iota (That guy was...
|
-
|
When using ASP.NET MVC you will eventually want to do a select (drop down) or even a multiple select list, and your first though might be to use <%= Html.DropDownList %>. Unfortunately you will soon notice that ASP.NET MVC always looks for a match between the name of the dropdown and a property on the model, and if it finds a match, it OVERRIDES the selected value(s) of the select list. Now of course not being able to reliably set the selected value(s) is a major problem – if you Google this you will get a ton of results and most people solve the issue by just changing the name of the Html.DropDownList(“name”) to something that doesn’t match a model property. Of course we can put this into the “hack” or “workaround” category...
|
-
|
This will be a quick and dirty post about how to get xVal 1.0 ( http://xval.codeplex.com/ ) to work with the new NHibernate Validator 1.2beta ( http://nhforge.org/media/p/7.aspx ). The problem is that xVal 1.0 ships with a NHibernate Validator (NHVal) Ruleset Provider which does not compile against the 1.2beta DLLs because of some API changes. Meanwhile, S#arp Architecture uses NHVal 1.2 so using those Dlls is a requirement for me. In the process of rewriting the NHVal ruleset provider I stripped out all XML rule definition support, so for my code to work you must be using NHVal attributes. With those disclaimers, here is the code: public class NHibernateValidatorRulesProvider : CachingRulesProvider { private readonly ValidatorMode configMode;...
|
-
|
In any project where you use an ORM you often have all of your domain classes inherit from a common base class. Among other things, your base class often contains your identity property. Mine has a protected IdT (this is the Id type) field called id, and a public getter called ID. 1: protected IdT id; 2: 3: public virtual IdT ID 4: { 5: get { return id; } 6: } One important and complex question is how to handle equality of two domain objects. This becomes very important for caching, using HashSets, and more. Before I share my solution I will mention that there are many implementations of base class equality out there, with S#arp Architecture’s standing out in my mind as a great though complex (maybe enterprise-level...
|
-
|
ASP.NET MVC comes with a UrlHelper class in the System.Web.Mvc.Controller.Url namespace, which you can access through the Url property of any controller. This provides some handy methods to get the url of an action or route, among other things. For example, Url.Action(“About”, “Home”) will return the string “/Home/About”, which is the relative url of the About action on the Home controller. I recently had a need to generate an absolute Url (to put in an email), so I wrote a quick extension method to the UrlHelper class that I thought might be useful to someone else. The code is as follows: 1: public static class UrlExtensions 2: { 3: public static string AbsoluteAction( this UrlHelper url, string action, string controller,...
|
-
|
This is the fourth and final post of a multi-part post series on writing simple auditing functionality for an ASP.NET application using NHibernate. The requirement was that every object modification event in the system should be logged by username and date. Specifically I don’t need to know exactly which properties were changed (just that a user was updated by whom at what time), but if you do need to save the changed properties there are plenty of hooks to do that. I’ll update this post with links to the next parts when they become available Part 1 Part 2 Part 3 Part 4 (you are here) Hooking up the NHibernate IInterceptor Now that we have written our IInterceptor, implemented as the AuditInterceptor class, we need to tell NHibernate...
|
-
|
This is the third post of a multi-part post series on writing simple auditing functionality for an ASP.NET application using NHibernate. The requirement was that every object modification event in the system should be logged by username and date. Specifically I don’t need to know exactly which properties were changed (just that a user was updated by whom at what time), but if you do need to save the changed properties there are plenty of hooks to do that. I’ll update this post with links to the next parts when they become available Part 1 Part 2 Part 3 (you are here) …… Part N The AuditObjectModification Method In Part 2 we wrote a bunch of tests for the AuditObjectModification method in the AuditInterceptor.cs class. This...
|