First release of NHibernate Entity Generator

by Mathieu 31. July 2008 22:42
Today I released a small code generator : from hbm files it can generate your entities and DAL, grab it while it's hot : http://www.codeplex.com/EntityGenerator :)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

NHibernate error : identifier type mismatch

by Mathieu 15. July 2008 20:34

If your entity has an id type of long, and you try to get it with ISession.Get<T>( 123 ), it will pass 123 as an int, and the following exception is thrown :

System.ArgumentException : identifier type mismatch
Parameter name : id

You can use ISession.Get<T>( (long)123 ), but it's not very clean. And it has caused some hair pulling to me :)

An alternative is to use :

id = Convert.ChangeType( id, typeof(T).GetProperty("Id").PropertyType);

ISession.Get<T>( id );

but still not very clean...
 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Tips

First release of SimpleValidation.NET, an ASP.NET validation framework

by Mathieu 3. July 2008 22:08

SimpleValidation.NET is a simple validation (!) framework, designed to work with ASP.NET and entities (or domain objects, or whatever you like :)). Its primary goal was simplicity of usage, and as i'm a big fan of "Show, dont tell" :

First, you have to create your entity. It can be an NHibernate mapped entity, for example. After that, you just tag it's properties :

public class UserEntity
{
    private string name;
    private int age;
    private string email;
 
    [Required("Name is required")]
    public string Name
    {
        get { return this.name; }
        set { this.name = value; }
    }
            
    [Required("Age is required")]
    [Range(0, 99, "Age must be in range {0} {1}")]
    public int Age
    {
        get { return this.age; }
        set { this.age = value; }
    }
 
    [Email("Email is invalid")]
    [Confirm("Please confirm your email")]
    [Required("Email is required")]
    public string Email
    {
        get { return this.email; }
        set { this.email = value; }
    }
}

After that, add a simple form to your page :

<div runat="server" id="inputForm" class="inputform">
<label>Name:</label>
<asp:TextBox runat="server" ID="Name" />
<label>Age:</label>
<asp:TextBox runat="server" ID="Age" />
<label>Email:</label>
<asp:TextBox runat="server" ID="Email" />
<label>Confirm Email:</label>
<asp:TextBox runat="server" ID="EmailConfirm" />
<asp:Button runat="server" ID="btn" Text="Test" />
</div>

And the WebValidationHelper control :

<SimpleValidation:WebValidationHelper ID="WebValidationHelper1" runat="server" 
EntityType="Samples.Entities.UserEntity, Samples.Entities" 
ValidatorDisplay="Dynamic"
ParentControl="inputForm" />

And here we go : corresponding validators are added automatically !

example1

How is it working ?

Very simply : you have to name your inputs with the same name as your entity's properties (convention over configuration here). Then, validators are added after the input control by default. You can also do the validation manually, or specify placeholders (they are located by prefix, like "ValidatorsForName"). For more details, you can look at the samples included in source code.

The project is hosted on codeplex here : http://www.codeplex.com/SimpleValidation/

kick it on DotNetKicks.com

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

SimpleValidation

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

Recent comments

Comment RSS

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in  anyway.

© Copyright 2008