【发布时间】:2019-12-11 11:17:50
【问题描述】:
我正在尝试将我的 .net Web API 应用程序迁移到 Service app Fabric 无状态 .net 核心 API。我想使用实体框架。当我尝试查询我的数据库表时,我收到错误“Failed to load C:\SfDevCluster\Data\_App\_Node_0\DRIHubType_App3\MUACAPIPkg.Code.1.0.0\x64\SNI.dll强>”
我尝试了所有方法,例如添加 sqlclient 4.0.0 参考,将框架更改为 4.6 等,但对我来说没有任何效果。
public class DatabaseContext : DbContext
{
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options)
{
}
public DbSet<Pubsuite> Pubsuite { get; set; }
}
==Startup Class code
services.AddDbContext<DatabaseContext>(opts => opts.UseSqlServer("server=srvername;database=dbname;User ID=user;password=password;"));
====Pubsuite class
public class Pubsuite
{
[Key]
public string username { get; set; }
public string pubsuites { get; set; }
}
public interface IPubsuiteRepository<T>
{
IEnumerable<T> GetPubsuites();
}
public class PubsuiteRepository : IPubsuiteRepository<Pubsuite>
{
readonly DatabaseContext _libraryContext;
public PubsuiteRepository(DatabaseContext context)
{
_libraryContext = context;
}
public IEnumerable<Pubsuite> GetPubsuites()
{
return _libraryContext.Pubsuite.ToList();
}
}
public class ValuesController : ControllerBase
{
private readonly IPubsuiteRepository<Pubsuite> _libraryRepository;
public ValuesController(IPubsuiteRepository<Pubsuite> libraryRepository)
{
_libraryRepository = libraryRepository;
}
// GET api/values
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
try
{
IEnumerable<Pubsuite> authors = _libraryRepository.GetPubsuites();
return new string[] { "value1", "value2" };
}
catch (Exception ex)
{
var mess = ex.Message;
return new string[] { mess };
}
}
}
}
错误:-
IEnumerable authors = _libraryRepository.GetPubsuites();
我在上面的行中遇到了错误。
【问题讨论】:
标签: c# asp.net-core asp.net-core-webapi appfabric