How should I create an alternate index for an entity in EF? RRS feed

  • Question


    Visual Basic 2010, .NET 4.0, Entity Framework 4.0, SQL Express


    Sometimes I need more than one key for an entity. For instance, entity Person, which is already uniqely identified by the Id property (an identity field), would also need to be uniquely identified by the LastName and FirstName properties (user-specified). How do I ensure that the database doesn't end up with 2 records with different Id info but the same name info? Should my code create an alternate index for the table, using T-SQL, when it creates the database? (I'm using Model-First.) Or should I do something else?

    PS. What if one more more of the fields are in a complex type? (i.e., Person.Name.Last, Person.Name.First)

    Robert Gustafson

    Tuesday, March 11, 2014 6:43 AM