Thursday, April 27, 2017

Resolving "Invalid column name" Exception

"System.Data.SqlClient.SqlException: Invalid column name 'Client_ClientId'."

A valid relationship to the Client entity model could not be determined. In our case, there were duplicate virtual references in the Client model (table) to the Document model (table).

The Document model had the following properties:

        public Nullable ClientId { get; set; }
        public virtual Client Client { get; set; }


However, the Client model had the following duplicate properties:

        public virtual ICollection ClientDocuments { get; set; }
        public virtual ICollection Documents { get; set; }

Removal of the duplicate eliminated the exception message.