I have two classes ( simplified for 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 contains a data set ( and other properties are not shown ). The Data class does not know about the DataContainer, but it cannot exist outside of one. For this, I use HasMany relationships.
I map the DataContainer as follows:
Id(x => x.Id);
HasMany<Data>(x => x.DataPoints)
.Not.KeyNullable()
.Cascade.All();
And the created 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 do not want [DataContainer] INT null, instead I want it to not allow nulls
[DataContainer] INT not null
I thought. KeyNullable () would do this, but it does not seem to work.
Thank.
source
share