【问题标题】:EntityFramework with service app fabric .net core stateless API SNI.dll not found errorEntityFramework with service app fabric .net core stateless API SNI.dll not found 错误
【发布时间】: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


    【解决方案1】:

    上述问题的解决方法是,安装visual studio 2019即可。其实最新的包是Microsoft.EntityFrameworkCore.SqlServer,Microsoft.EntityFrameworkCore是3.1。我觉得更适合2019年。

    【讨论】:

      猜你喜欢
      • 2019-04-07
      • 1970-01-01
      • 2018-09-15
      • 2019-05-12
      • 1970-01-01
      • 1970-01-01
      • 2016-09-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多