private static void AssertHasValidKey(ActiveRecordModel model)
{
// Nested types do not have primary keys
if (model.IsNestedType) return;
// Need to make the check this way because of inheritance,
// where the current class doesn't have
// a primary key but the base class does
ActiveRecordModel tmpModel = model;
while(tmpModel != null && tmpModel.PrimaryKey == null && tmpModel.CompositeKey == null)
{
tmpModel = tmpModel.Parent;
}
if (tmpModel != null && tmpModel.PrimaryKey != null && tmpModel.CompositeKey != null)
{
throw new ActiveRecordException(
String.Format(
"A type cannot have a primary key and a composite key at the same time. Check type {0}",
model.Type.FullName));
}
if (tmpModel == null || tmpModel.PrimaryKey == null && tmpModel.CompositeKey == null)
{
throw new ActiveRecordException(String.Format(
"A type must declare a primary key. Check type {0}", model.Type.FullName));
}
}