简体   繁体   English

EntityFramework with service app fabric .net core stateless API SNI.dll not found 错误

[英]EntityFramework with service app fabric .net core stateless API SNI.dll not found error

I am trying to migrate my .net Web API application to Service app Fabric stateless .net core API.我正在尝试将我的 .net Web API 应用程序迁移到 Service app Fabric 无状态 .net 核心 API。 I want to use the entity framework.我想使用实体框架。 When I am trying to query on my db table so I am getting error " Failed to load C:\\SfDevCluster\\Data\\_App\\_Node_0\\DRIHubType_App3\\MUACAPIPkg.Code.1.0.0\\x64\\SNI.dll "当我尝试查询我的数据库表时,出现错误“无法加载 C:\\SfDevCluster\\Data\\_App\\_Node_0\\DRIHubType_App3\\MUACAPIPkg.Code.1.0.0\\x64\\SNI.dll

I tried all the things like adding sqlclient 4.0.0 reference, changed the framework to 4.6 etc. but nothing is working for me.我尝试了所有的事情,比如添加 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 };
                }

            }
        }
    }

error:-错误:-

IEnumerable authors = _libraryRepository.GetPubsuites(); IEnumerable 作者 = _libraryRepository.GetPubsuites();

I am getting error on the above line.我在上面的行中遇到错误。

The solution to the above problem is, just install the visual studio 2019. Actually the latest package of Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore is 3.1 .解决上述问题的方法是,安装visual studio 2019即可。其实Microsoft.EntityFrameworkCore.SqlServer的最新包,Microsoft.EntityFrameworkCore是3.1。 I think it is more suitable for 2019.我认为它更适合2019年。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM