需要 System.String,得到 System.Guid
我希望有一个非常简单的解释为什么我会收到此错误。
我正在使用 S#arpArcitecture 1.6。在 64 位 Windows 7 安装上。
以下代码的第 3 行给出错误:
{"Provided id of the error type. Expected: System.String, got System.Guid"} System.Exception {NHibernate.TypeMismatchException}
1 public Category GetCategory(Guid id)
2 {
3 Category cat = categoryRepository.Get(id);
4 return cat;
5 }
Supporting信息
表 (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
{ }
I am hoping there is a very simple explanation why I am getting this error.
I am using S#arpArcitecture 1.6. on a 64bit Windows 7 install.
Line 3 of the following code gives the error:
{"Provided id of the wrong type. Expected: System.String, got System.Guid"} System.Exception {NHibernate.TypeMismatchException}
1 public Category GetCategory(Guid id)
2 {
3 Category cat = categoryRepository.Get(id);
4 return cat;
5 }
Supporting Info
Table (SQL Server 2008)
CREATE TABLE [dbo].[MasterCategories] (
[masterCategoryId] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[organizationId] [nchar](5) NOT NULL,
[categoryNumber] [nvarchar](25) NOT NULL
)
Entity Definition
public class Category : EntityWithTypedId<Guid>
Fluent Mapping
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();
}
Repository Interface
public interface ICategoryRepository : IRepositoryWithTypedId<Category,Guid>
{
}
Repository
public class CategoryRepository :
RepositoryWithTypedId<Category,Guid>,
ICategoryRepository
{ }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的映射需要是这样的:
I think your mapping needs to be like this: