-1

Conference我对这张桌子有问题。错误是:

列名“Conference_ConferenceID”无效

在此处输入图像描述

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;

        }
    }
}
4

1 回答 1

0

当代码和数据库之间不匹配时,我会收到此错误,因为代码希望在数据库中找到列但它们不存在。当数据库未更新以匹配代码中的更改时,就会发生这种情况。我建议查看当您收到该错误时被击中的数据库,也许它没有在您期望的地方查看。

于 2013-05-16T18:23:49.923 回答