Asp.net web api 使用VS 2013和实体框架6的Restful WebApi Connundrum
我已经构建了一个WebApi,每个对象都有模型和控制器,但我不明白的是为什么我的Context.cs有时使用控制器,有时使用模型:请参阅下面的代码:Asp.net web api 使用VS 2013和实体框架6的Restful WebApi Connundrum,asp.net-web-api,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 :
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; }
}
}
使用系统;
使用System.Collections.Generic;
使用System.Data.Entity;
使用System.Linq;
使用System.Web;
名称空间RxSurvey.Models
{
公共类RxSurveyContext:DbContext
{
//您可以将自定义代码添加到此文件。更改不会被覆盖。
//
//如果希望实体框架删除并重新生成数据库
//无论何时更改模型架构,都会自动执行数据迁移。
//有关更多信息,请参阅文档:
// http://msdn.microsoft.com/en-us/data/jj591621.aspx
公共RxSurveyContext():基(“名称=RxSurveyContext”)
{
}
public System.Data.Entity.DbSet类别{get;set;}
public System.Data.Entity.DbSet检查{get;set;}
public System.Data.Entity.DbSet定义{get;set;}
public System.Data.Entity.DbSet{get;set;}
public System.Data.Entity.DbSet项{get;set;}
public System.Data.Entity.DbSet行{get;set;}
public System.Data.Entity.DbSet调查{get;set;}
public System.Data.Entity.DbSet节{get;set;}
public System.Data.Entity.DbSet登录名{get;set;}
public System.Data.Entity.DbSet日志{get;set;}
public System.Data.Entity.DbSet设置{get;set;}
public System.Data.Entity.DbSet{get;set;}
public System.Data.Entity.DbSet vwStates{get;set;}
public System.Data.Entity.DbSet{get;set;}
}
}
多谢各位
保罗嗯,我算出来了。添加类时,它们有时作为控制器启动,有时作为模型启动。如果需要,请确保将它们都设置为模型