代码之家  ›  专栏  ›  技术社区  ›  Jason Watts

需要System.String,得到System.Guid

  •  3
  • Jason Watts  · 技术社区  · 14 年前

    我正在使用S#arpArcitecture 1.6。在64位Windows7上安装。

    {“提供了错误类型的id。应为:System.String,get System.Guid“}System.Exception{NHibernate.TypeMismatchException}

    1 public Category GetCategory(Guid id)
    2    {
    3        Category cat = categoryRepository.Get(id);
    4        return cat;
    5    }
    

    表(SQL Server 2008)

    CREATE TABLE [dbo].[MasterCategories] (
        [masterCategoryId] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
        [organizationId] [nchar](5) NOT NULL,
        [categoryNumber] [nvarchar](25) NOT NULL
    )
    

    实体定义

    public class Category : EntityWithTypedId<Guid>
    

    public void Override(AutoMapping<Category> mapping)
        {
            mapping.Table("MasterCategories");
    
            mapping.Id(x => x.Id).Column("masterCategoryId");
            mapping.Map(x => x.Number).Column("categoryNumber");
    
            mapping.References(x => x.Organization)
                .Column("organizationId")
                .Cascade.All();
        }
    

    存储库接口

    public interface ICategoryRepository : IRepositoryWithTypedId<Category,Guid>
    {
    }
    

    存储库

    public class CategoryRepository : 
                 RepositoryWithTypedId<Category,Guid>, 
                 ICategoryRepository
    { }   
    
    1 回复  |  直到 14 年前
        1
  •  0
  •   Chris Conway    14 年前

    我认为你的地图应该是这样的:

    public void Override(AutoMapping<Category> mapping)
    {
        mapping.Table("MasterCategories");
        mapping.Id(x => x.Id).Column("masterCategoryId").GeneratedBy.Guid();
        mapping.Map(x => x.Number).Column("categoryNumber");
    
        mapping.References(x => x.Organization)
                .Column("organizationId")
                .Cascade.All();
    }