The problem arises when creating cascading foreign keys using the following models, in which only one model (UserAddition) knows another (User), and there is no way to add the UserAddition property to the User class:
class User {
public virtual Guid Id { get; set; }
}
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 must have a foreign key for the user that is set to ON DELETE CASCADE (setting ON UPDATE is not important).
When using the following mapping class, the foreign key is always set to "No action", even if it indicated otherwise in the mapping. Did I miss something?
public class UserAdditionMapping : ClassMap<UserAddition>
{
public TrainerToEmployeeMapping()
{
this.Id(x => x.Id);
this.References(x => x.RemoteUser).ForeignKey().Cascade.All();
}
}
The database used is Microsoft SQL Server 11.
Thank.
Fionn source
share