The problem occurs with the creation of cascading foreign keys using the following Models, where only one Model (UserAddition) knows the other (User) and there is no possibility to add a UserAddition property to the User class:
class User {
public virtual Guid Id { get; set; }
// Other fields of no relevance
}
class UserAddition {
public virtual Guid Id { get; set; }
public virtual User RemoteUser {get; set; }
public virtual string AdditionalData {get; set; }
}
The generated SQL Table for UserAddition should have an foreign key to User which is set to ON DELETE CASCADE (the setting of ON UPDATE is not important).
When using the following mapping class, the foreign key is always set to "No Action", even though it's specified otherwise in the mapping. Am I missing something?
public class UserAdditionMapping : ClassMap<UserAddition>
{
public TrainerToEmployeeMapping()
{
this.Id(x => x.Id);
this.References(x => x.RemoteUser).ForeignKey().Cascade.All();
}
}
The Database in use is an Microsoft SQL Server 11.
Thanks.