2013-05-16 4 views
-1

У меня проблема с этим столом Conference. Ошибка:Entity Framework: Недопустимое имя столбца

Неверное имя столбца «Conference_ConferenceID»

enter image description here

namespace MeetingBoard.Model 
{ 
    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel.DataAnnotations; 
    using System.Linq; 
    using System.Web.Script.Serialization; 

    using MeetingBoard.Model.Helpers; 
    using System.ComponentModel.DataAnnotations.Schema; 
    /// <summary> 
    /// A model of the Conference entity. Contains functionality to serialize the entity to JSON as well. 
    /// </summary> 
    public class Conference 
    { 
     [Key] 
     public int ConferenceID { get; set; } 

     public string Title { get; set; } 
     public string Content { get; set; } 
     public int CreatorID { get; set; } 

     public string Location { get; set; } 
     public DateTime SubmissionDate { get; set; } 


     [ForeignKey("CreatorID")] 
     public virtual User Creator { get; set; } 

     public int[] RelatedProjectsIDs { get; set; } 
     public virtual ICollection<ProjectTag> RelatedProjectTags { get; set; } 

     public DateTime CreatedOn 
     { 
      get { return (this.dateCreated == default(DateTime)) ? DateTime.UtcNow : this.dateCreated; } 
      set { this.dateCreated = value; } 
     } 
     private DateTime dateCreated = default(DateTime); 

     public virtual ICollection<Group> RelatedGroups { get; set; } 

     public Conference() 
     { 
      RelatedGroups = new List<Group>(); 
     } 


     /// <summary> 
     /// Generates an object that can be serialized by the JSON serializer of MVC 
     /// </summary> 
     /// <param name="happening">An Conference.</param> 
     /// <returns></returns> 
     public static Object ToJsonObject(Conference conference) 
     { 
      int[] project_ids = conference.RelatedProjectTags.Select<ProjectTag, int>(pt => pt.ProjectID).ToArray(); 



      return new Conference_JSON 
      { 
       id = conference.ConferenceID, 
       title = conference.Title, 
       Content = conference.Content, 
       created_timestamp_UTC = Util.DateTimeToMilliTimeStamp(conference.CreatedOn), 
       SubmissionDate = conference.SubmissionDate, 
       Location = conference.Location, 

       creator_avatar = conference.Creator.Avatar, 
       creator_fullname = conference.Creator.Name, 
       creator_id = conference.Creator.UserID, 

       project_ids = project_ids, 

      }; 
     } 
     /// <summary> 
     /// Instantiates a new Conference object based on the json data. 
     /// </summary> 
     /// <param name="json_data">The json data needs to have the structure as specified in the private Conference_JSON object.</param> 
     /// <returns>A new Conference object. The related projects are referenced using an integer array containing project ids.</returns> 
     public static Conference FromJson(String json_data) 
     { 
      JavaScriptSerializer serializer = new JavaScriptSerializer(); 
      Conference_JSON conference_object = serializer.Deserialize<Conference_JSON>(json_data); 

      return FromJsonObject(conference_object); 

     } 

     /// <summary> 
     /// Instantiates a new Conference object based on the private Conference_JSON object. 
     /// </summary> 
     /// <param name="json_data">The object needs to be an instance of the private Conference_JSON object.</param> 
     /// <returns>A new Conference object. The related projects are referenced using an integer array containing project ids.</returns> 
     public static Conference FromJsonObject(Object conference_object) 
     { 
      Conference_JSON conference_json = (Conference_JSON)conference_object; 

      Conference conference = new Conference 
      { 
       ConferenceID = conference_json.id, 
       Title = conference_json.title, 
       Content = conference_json.Content, 
       RelatedProjectsIDs = conference_json.project_ids, 
       Location = conference_json.Location, 
       SubmissionDate = conference_json.SubmissionDate, 

      }; 
      return conference; 
     } 

     /// <summary> 
     /// Defines the structure of the json objects that ar communicated to and from the Frontend. 
     /// </summary> 
     private class Conference_JSON 
     { 
      /// <summary> 
      /// The Conference identifier. 
      /// </summary> 
      public int id; 
      public string title; 
      public string Content; 

      /// <summary> 
      /// An numeric representation of the time, in milliseconds from Unix Epoch, UTC timezone. 
      /// </summary> 
      public double created_timestamp_UTC; 

      public string creator_fullname; 
      public int creator_id; 
      public string creator_avatar; 

      /// <summary> 
      /// Related projects. 
      /// </summary> 
      public int[] project_ids; 
      public string Location; 
      public DateTime SubmissionDate; 

     } 
    } 
} 
+0

сначала код или БД. Где ошибка? SSMS или VS? –

+0

Обычно такая ошибка возникает, если в базе данных не найден соответствующий столбец. Я предлагаю вам проверить имя столбца в соответствующей таблице. –

+0

Является ли это ошибкой компиляции или времени выполнения? –

ответ

0

Я получаю эту ошибку, когда существует несоответствие между кодом и БД, в том смысле, что код ожидает найти столбцы в БД, но они там не существуют. Это происходит, когда БД не обновляется, чтобы соответствовать изменениям в коде. Я бы предложил посмотреть на базу данных, которая попадает, когда вы получаете эту ошибку, может быть, она не смотрит, где вы ожидаете.

Смежные вопросы