我正在编写一个使用 NHibernate 访问数据库的 C# 应用程序。我的数据源之一是名为 content_profile
的 View (不是表)。我使用 NHibernate 属性创建了以下示例类:
[Class(Table = "content_profile")]
public class ContentProfile
{
[Id(0, TypeType = typeof(int), Name = @"Id"), Generator(2, Class = @"identity"), Column(1, Name = @"Id")]
public virtual int Id { get; set; }
[NotEmpty]
[MinLength(1)]
public virtual string Name { get; set; }
[Property]
public virtual DateTime? CreationDate { get; set; }
[ManyToOne(Lazy = Laziness.False, Column = @"author_id")]
public virtual User Owner { get; set; }
}
尝试更新架构时出现以下错误:
NHibernate.Tool.hbm2ddl.SchemaUpdate [(null)] - Unsuccessful: alter table public.content_profile add constraint FK280FFEFD6A68A1F9 foreign key (author_id) references public.users
Npgsql.NpgsqlException:
"content_profile" - is not a table
我如何告诉 NHibernate 它确实是一个 View ,而不是一个表,并且不能在模式更新时创建索引?
最佳答案
您可以通过添加 SchemaAction.None
来指定不应对某个类映射的架构执行任何操作,从未真正使用过属性,因为它缺少功能,但它应该具有类似 [Class(SchemaAction="None")]
关于c# - NHibernate 尝试为 View 创建索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21253414/