Вопрос

I am trying to make an nHibernate entity that implements Microsoft.AspNet.Identity.IUser but I want to use Guids for the Id key property. I am building this in a Castle ActiveRecord environment.

I'm writing a property in my User class per the interface like so:

public class User : IUser
{
    public virtual string Id { get; set; }
    public virtual string UserName { get; set; }
}

What I'd like to be able to do is populate the Id column with a generated Guid in the database, but populate the Id property in the entity with a Guid string.

I thought I'd be good with overriding NHibernate.Id.TableGenerator like so:

public class GuidStringGenerator : TableGenerator
{
    public override object Generate(ISessionImplementor session, object obj)
    {
        return Guid.NewGuid().ToString();
    }
}

... but now I think won't actually accomplish what I want; it seems this would make a string value in the database instead of a Guid.

Any wisdom on how this would be accomplished?

Это было полезно?

Решение

Hello Jeremy Holovacs,

you could implement the Id-Property of IUser explicit.

public class User : IUser
{
  public virtual Guid Id { get; set; }
  string IUser.Id{get{return this.Id.ToString();}}
  public virtual string UserName { get; set; }
}

Greetings Juy Juka

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top