将类库项目从 .netcore2.2 迁移到 .netcore 3.1 时,出现以下错误:
错误 CS1061“IMutableEntityType”不包含“Cosmos”的定义,并且找不到接受“IMutableEntityType”类型的第一个参数的可访问扩展方法“Cosmos”(您是否缺少 using 指令或程序集引用?)
在.netcore2.2项目中,我使用了以下 nuget 包:
现在,作为迁移过程的一部分,我已将上述所有 nuget 软件包更新为最新版本。
她去我的 DbContext 类:
public class MyDbContext : DbContext
{
public MyDbContext(DbContextOptions<MyDbContext> options): base(options)
{
}
protected MyDbContext()
{
}
public DbSet<Address> Address { get; set;}
public DbSet<Languages> Languages { get; set;}
public DbSet<Contacts> Contacts { get; set;}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
OneCollectionPerDbSet(modelBuilder);
}
private void OneCollectionPerDbSet(ModelBuilder modelBuilder)
{
var dbSets = typeof(MyDbContext).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.PropertyType.IsGenericType …Run Code Online (Sandbox Code Playgroud) 我已经为Visual Studio代码编辑器安装了ESLint插件,它显示它也已安装,但我仍然看到错误:在编辑器窗口顶部找不到Visual Studio Code的ESLint配置,如下面的屏幕截图所示:
任何人都可以帮助我知道我在这里缺少什么.
我将一个asp.net core项目从2.2版本迁移到3.1版本。我已经添加了所有依赖项和 docker 相关组件。它编译正常,但在运行项目时我收到以下错误:
抛出异常:Microsoft.Extensions.DependencyInjection.dll 中的“System.AggregateException” Microsoft.Extensions.DependencyInjection.dll 中发生类型“System.AggregateException”的未处理异常:“无法构造某些服务”堆栈跟踪:位于Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable
1 serviceDescriptors, ServiceProviderOptions options) at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options) at Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory.CreateServiceProvider(IServiceCollection containerBuilder) at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter1.CreateServiceProvider(对象containerBuilder)在Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()在Microsoft.Extensions.Hosting.HostBuilder.Build()在Sample.API.Program。 /src/QueryStack/Sample.API/Program.cs 中的 Main(String[] args):第 20 行 程序“kubectl.exe”已退出,代码为 -1 (0xffffffff)。
这是我的代码:
程序.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Sample.API
{
public class Program
{
public static void Main(string[] args)
{
// Use the W3C Trace Context format to propagate distributed trace identifiers.
// See https://devblogs.microsoft.com/aspnet/improvements-in-net-core-3-0-for-troubleshooting-and-monitoring-distributed-apps/ …Run Code Online (Sandbox Code Playgroud) 我将我的数据层类库项目从 .NETCore 2.2 升级到 .NETCore3.1,并将 Nuget 包(如 EntityFrameWork Core)从 2.2.0 升级到 EFCore 3.1.0。
然后我在验证以下代码时遇到如下错误:
代码:
private async Task<List<CountryDTO>> GetCountriesDataAsync(int languageId)
{
int pageNo = 1, pageSize = 100;
var images = await _cacheService.GetAllAsync("imagesCacheKey");
return await _dbContext.Countries
.Where(cc => cc.IsPublished.Equals(true)
&& cc.LanguageId.Equals(languageId))
.Select(co => new CountryDTO
{ Uuid = co.CountryId,
PNGImagePath = images.FirstOrDefault(im => im.ImageId.Equals(co.PNGImageId))
.FilePath,
SVGImagePath = images.FirstOrDefault(im => im.ImageId.Equals(co.SVGImageId))
.FilePath,
DisplayName = co.DisplayName,
DisplayNameShort = co.DisplayName,
Name = Helper.ReplaceChars(co.DisplayName),
Path = Helper.ReplaceChars(co.DisplayName),
CompleteResponse = true})
.Skip((pageNo - 1) * …Run Code Online (Sandbox Code Playgroud) 我有一个如下所述的jqGrid:
UsersList.aspx
<div id="users" class="grid-right">
<h3>Users</h3>
<table id="client-group-users-list"></table>
<div id="client-group-users-list-pager"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
userlistgroup.js
function createUsersGrid(getUsersForClientGroupUrl) {
$('#client-group-users-list').jqGrid({
height: "auto",
width: "590",
url: getUsersForClientGroupUrl + "?random=" + Math.random(),
rowNum: 10,
mtype: 'POST',
viewrecords: true,
postData: { clientGroup: getClientGroupId(), active: true },
datatype: 'json',
colNames: ['ClientGroupID', 'Login', 'Role'],
//pgbuttons: false,
//pgtext: null,
//viewrecords: false,
gridview: true,
colModel: [
{ name: 'ClientGroupID', index: 'ClientGroupID', hidden: true },
{ name: 'Login', index: 'Login', search: false, width: 130, sorttype: "string" },
{ name: 'Role', index: 'Role', …Run Code Online (Sandbox Code Playgroud) 我有一个asp.net core 2 Web API,它将在以下环境中部署:
INT,QA,STAGE,生产环境。
基于上述,我需要appsettings.<EnvironmentName>.json为每个环境提供文件。从以下链接:https : //docs.microsoft.com/zh-cn/aspnet/core/fundamentals/environments?view=aspnetcore-2.1 ,我看到了
如果是本地开发环境,则将名为ASPNETCORE_ENVIRONMENT的环境变量设置为“开发”。在未设置ASPNETCORE_ENVIRONMENT的部署中,默认值为生产
我想知道在appsettings.<EnvironmentName>.json为INT,QA和STAGE环境准备文件时需要采取哪些步骤?我是否需要为每个环境Web服务器显式设置环境:
设置ASPNETCORE_ENVIRONMENT =开发。
任何人都可以通过提供指导来帮助我吗?
我使用 asp.net web api 2 和 EntityFramework 6 开发了以下代码片段。
public class TestController : BaseApiController
{
private readonly ITestService _testService;
private readonly ICommonService _commonService;
private readonly IImageService _imageService;
public TestController(ITestService testService, ICommonService commonService, IImageService imageService)
{
_testService = testService;
_commonService = commonService;
_imageService = imageService;
}
[Route("test")]
public IHttpActionResult Get()
{
var resp = _testService.GetDetailsForLocation(locale);
return Ok(resp);
}
}
public class BaseApiController : ApiController
{
public string locale
{
get
{
if (Request.Headers.Contains("Accept-Language"))
{
return Request.Headers.GetValues("Accept-Language").First();
}
else
{
return string.Empty; …Run Code Online (Sandbox Code Playgroud) 我正在使用ASP.NET core 2.2开发Web api。我在存储库类中具有以下方法:
public async Task<Articles> AddAsync(Articles article)
{
return await _context.Articles.AddAsync(article);
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Cannot implicitly convert type 'Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<Author.Command.Persistence.DBContextAggregate.Articles>' to 'Author.Command.Persistence.DBContextAggregate.Articles'
Run Code Online (Sandbox Code Playgroud)
在这里,我试图使用AddAsync版本来保存数据。
谁能帮助我提供解决此问题的指导?
我有 asp.net core 3.1 web api 项目,代码如下:
启动.cs
public virtual void ConfigureServices(IServiceCollection services) =>
services
.AddFrameworkServices()
.AddApplicationInsights(this.configuration)
.AddResponseCompression()
.AddCustomConfigureOptions();
Run Code Online (Sandbox Code Playgroud)
CustomServiceCollectionExtensions.cs
public static IServiceCollection AddCustomConfigureOptions(this IServiceCollection services) =>
services
.ConfigureOptions<ConfigureAuthenticationOptions>();
.ConfigureOptions<ConfigureJwtBearerOptions>();
Run Code Online (Sandbox Code Playgroud)
配置身份验证选项.cs
public class ConfigureAuthenticationOptions : IConfigureOptions<AuthenticationOptions>
{
public void Configure(AuthenticationOptions options) =>
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
}
Run Code Online (Sandbox Code Playgroud)
配置JwtBearerOptions
public class ConfigureJwtBearerOptions : IConfigureOptions<JwtBearerOptions>
{
private readonly IConfiguration configuration;
public ConfigureJwtBearerOptions(IConfiguration configuration) => this.configuration = configuration;
public void Configure(JwtBearerOptions options)
{
options.Authority = configuration[C.AppKeys.AADInstance] + configuration[C.AppKeys.AADTenantID];
options.Audience = configuration[C.AppKeys.AADAudience];
}
}
Run Code Online (Sandbox Code Playgroud)
在调试时我发现ConfigureJwtBearerOptions.cs文件的Configure方法没有被触发 …
我正在尝试使用 Visual Studio 2022(企业版)使用 .NET 7 asp.net core Web api 应用程序的托管标识从 appsettings.Development.json 文件中读取值
这是 Program.cs 的代码:
var builder = WebApplication.CreateBuilder(args);
var config = builder.Configuration;
// Add AzureKeyVault
builder.Host.ConfigureAppConfiguration((context, appConfig) =>
{
var objBuiltConfig = appConfig.Build();
var userAssignedClientId = objBuiltConfig[AppKeys.UserAssignedClientId];
var objSecretClient = new SecretClient(new Uri(objBuiltConfig[AppKeys.KeyVaultURL]),
new DefaultAzureCredential(new DefaultAzureCredentialOptions
{
ManagedIdentityClientId = userAssignedClientId
}));
config.AddAzureKeyVault(objSecretClient, new KeyVaultSecretManager());
});
Run Code Online (Sandbox Code Playgroud)
在代码编辑器中我看到警告:
建议使用 webapplicationbuilder.configuration 而不是 configureappconfiguration
即使在调试时我也没有得到数据。
任何人都可以帮助我提供一些代码示例,该示例将作为我的实现的参考
====================更新======================
var userAssignedClientId = config[AppKeys.UserAssignedClientId];
var keyVaultURL = config[AppKeys.KeyVaultURL];
builder.Configuration.AddAzureKeyVault(new Uri(uriString: keyVaultURL), new
DefaultAzureCredential(new DefaultAzureCredentialOptions { …Run Code Online (Sandbox Code Playgroud) c# ×7
c#-8.0 ×2
ef-core-3.1 ×2
.net-7.0 ×1
asp.net-core ×1
eslint ×1
graphql ×1
graphql.net ×1
jqgrid ×1
jquery-ui ×1
linq ×1
react-jsx ×1