Question

I'm writing a C# application that uses NHibernate to access the database. One of my data sources is a view (not a table) named content_profile. I have created the following sample class using NHibernate Attributes:

[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; }
}

When trying to update schema I get the following error:

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

How do I tell NHibernate that it is indeed a view, not a table, and indexes must not be created on schema update?

Was it helpful?

Solution

You can specify that there should not be done any action on the schema of a certain class map by adding SchemaAction.None, never really used attributes because it lacks features but it should have something like [Class(SchemaAction="None")]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top