2013-05-16 147 views
-1

我有这个Conference表的问题。错误是:实体框架:无效的列名称

无效的列名称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

先编码或DB先编码。抛出的错误在哪里? SSMS或VS? –

+0

如果在数据库中找不到匹配列,通常会出现这样的错误。我建议你在相应的表中检查列名。 –

+0

这是一个编译或运行时错误? –

回答

0

我得到这个错误时,有代码和数据库之间的不匹配,在这个意义上,代码希望在数据库中找到列,但它们不存在于那里。这发生在数据库未更新以匹配代码中的更改时发生。我建议你看看当你遇到错误时正在被打的数据库,也许它没有看到你期望的地方。

相关问题