I have two classes (simplified for the example):
public class Data
{
public int Id {get; set;}
public string Value { get; set; }
}
public class DataContainer
{
public int Id {get; set;}
public IList<Data> DataPoints { get; set; }
}
Basically the DataContainer class has a collection of Data (and other properties not shown). The Data class does not know about DataContainer but it cannot exist outside of one. I use a HasMany relationship for this.
I map DataContainer like this:
Id(x => x.Id);
HasMany<Data>(x => x.DataPoints)
.Not.KeyNullable()
.Cascade.All();
And the generated SQL for Data looks like this:
create table [Data] (
[Id] INT IDENTITY NOT NULL,
[DataContainer] INT null,
primary key ([Id])
)
alter table [Data]
add constraint FK173EC9226585807B
foreign key ([DataContainer])
references [DataContainer]
The problem is that I don't want [DataContainer] INT null, instead I want it not allow nulls
[DataContainer] INT not null
I thought .Not.KeyNullable() would do this but it doesn't seem to work.
Thanks.