Skip to content

Model Creation Bug When Using an Entity with a Name Less than 4 Characters #66

@jjbutera

Description

@jjbutera

I get the following error because I have an entity called "Set" (like a music set) in my model.

StartIndex cannot be less than zero. Parameter name: startIndex at System.String.Remove(Int32 startIndex, Int32 count) at SQLite.CodeFirst.Utility.SqliteAssociationType.IsSelfReferencing(AssociationType associationType) at SQLite.CodeFirst.Utility.SqliteAssociationType..ctor(AssociationType associationType, EntityContainer container) ...

This code throws the exception. I would check the ToRole.Name length first. If less than 4, return false;

private const string SelfReferencingPostfix = "Self";
private static bool IsSelfReferencing(AssociationType associationType)
{
            return associationType.Constraint.ToRole.Name.Remove(associationType.Constraint.ToRole.Name.Length - SelfReferencingPostfix.Length, SelfReferencingPostfix.Length) == associationType.Constraint.FromRole.Name;
}

Maybe change to:

private static bool IsSelfReferencing(AssociationType associationType)
{
    var toRoleName = associationType.Constraint.ToRole.Name;
    if (toRoleName.Length < 4)
        return false;

    return toRoleName.Remove(toRoleName.Length - SelfReferencingPostfix.Length, SelfReferencingPostfix.Length) == associationType.Constraint.FromRole.Name;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions