Restful WebApi Connundrum使用VS 2013和Entity Framework 6

时间:2015-08-06 18:32:15

标签: asp.net-web-api

我已经构建了一个WebApi,并为我的每个对象都有模型和控制器,但我不明白的是为什么我的Context.cs有时使用控制器,有时使用模型:请参阅下面的代码:

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace RxSurvey.Models
{
    public class RxSurveyContext : DbContext
    {
        // You can add custom code to this file. Changes will not be overwritten.
        // 
        // If you want Entity Framework to drop and regenerate your database
        // automatically whenever you change your model schema, please use data migrations.
        // For more information refer to the documentation:
        // http://msdn.microsoft.com/en-us/data/jj591621.aspx

        public RxSurveyContext() : base("name=RxSurveyContext")
        {
        }

        public System.Data.Entity.DbSet<RxSurvey.Controllers.Category> Categories { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Controllers.Check> Checks { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Controllers.Definition> Definitions { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Controllers.Insurer> Insurers { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Controllers.Item> Items { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Controllers.Line> Lines { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Controllers.Survey> Surveys { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Controllers.Section> Sections { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Controllers.Login> Logins { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Controllers.Log> Logs { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Controllers.Setting> Settings { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Models.vwRating> vwRatings { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Models.vwState> vwStates { get; set; }

        public System.Data.Entity.DbSet<RxSurvey.Controllers.vwSurvey> vwSurveys { get; set; }

    }
}

谢谢 保罗

1 个答案:

答案 0 :(得分:0)

好吧,我把它解决了。添加类时,有时它们作为控制器启动,有时作为模型启动。如果那是你想要的,请确保将它们全部设置为模型。