Reputation: 191058
How do I escape keyword conflicts when NHibernate generates my column names using FluentNHibernate?
NHibernate generated this for me and "Key" is a conflict.
create table Setting (
Key NVARCHAR(MAX) not null,
Value NVARCHAR(MAX) null,
primary key (Key)
)
Upvotes: 2
Views: 735
Reputation: 1228
I had a similar problem. The fix is to use FluentNHibernate's Column property part to put brackets around the column name for the key property.
Here is an entity with a problematic Key property:
public class MyEntity
{
public virtual int Id { get; set; }
public virtual string Key { get; set; }
}
Here is how to specify the column name in the mapping:
public class MyEntityMap : ClassMap<MyEntity>
{
public MyEntityMap()
{
Id(x => x.Id).GeneratedBy.Assigned();
// Note the brackets around Key
Map(x => x.Key).Column("[Key]").Not.Nullable();
}
}
Upvotes: 1
Reputation: 351758
Try this:
create table Setting (
[Key] NVARCHAR(MAX) not null,
Value NVARCHAR(MAX) null,
primary key (Key)
)
SQL Server allows you to escape reserved words by putting square brackets around the text.
Upvotes: -1