This project has moved. For the latest updates, please go here.

Add a helpful exception message to ValidateEntityCore in Relation.cs

Sep 24, 2013 at 10:06 PM
It was painful to get to the root cause using TDD because the error that bubbling up "RelationError" was not much help and it required stepping through Efforts actual code rather than just using a nuget package.

In Relation.cs something like the following would be better than the current error message.
        private void ValidateEntityCore(TForeign foreign)
            TForeignKey foreignKey = this.foreignIndex.KeyInfo.SelectKey(foreign);

            // Empty foreign key means, that it does not refer to anything
            if (this.foreignIndex.KeyInfo.IsEmptyKey(foreignKey))

            TPrimaryKey primaryKey = this.convertForeignToPrimary.Invoke(foreignKey);

            if (!this.primaryIndex.Contains(primaryKey))

                var tableName = this.foreignIndex.Table.EntityType.Name;
                var column = this.foreignIndex.KeyInfo.EntityKeyMembers[0].Name;
                var primaryTableName = this.primaryIndex.Table.EntityType.Name;
                var message = string.Format(
                    "The table [{0}] has a foreign key [{1}] with the value of {2}. The value that does not exist in foreign table {3}.", 
                    tableName, column, primaryKey, primaryTableName);

                throw new ForeignKeyViolationException(message);
Awesome Library though.
Sep 24, 2013 at 10:21 PM
You are right! I will definitely add something like this. Thank you for the deep research!
Oct 31, 2013 at 6:39 AM
Edited Oct 31, 2013 at 7:19 AM
Can I add a +1 to this? Am hitting this exact issue at the moment.

Edit: Disregard that, just updated to the latest beta and I can see this has been integrated.

Edit 2: we're getting the error:
The key value [foo] does exists in the referenced table

Not sure if this is just a typo?
Nov 2, 2013 at 5:32 PM
Yes, this is a type, thank you for the report.