小编Mau*_*tti的帖子

SQL Server:事务中的"DROP TABLE"会导致隐式提交吗?

我的问题很简单,但在创建此交易后我仍然怀疑.如果我执行以下代码:

BEGIN TRANSACTION
      DROP TABLE Table_Name
Run Code Online (Sandbox Code Playgroud)

我可以执行恢复丢弃表的ROLLBACK TRANSACTION吗?我问,因为我不知道'对象浏览器'中发生了什么,我没有发现任何关于这个主题的问题,所以我认为这可能是一个有用的问题.

sql transactions drop-table

21
推荐指数
2
解决办法
1万
查看次数

简单注入器:使用ILoggerFactory.CreateLogger注册ILogger <T> <T>()

我正在使用一个利用Simple Injector作为依赖注入器的项目.另一方面,该项目使用Microsoft.Extensions.Logging来记录某些类中发生的事件.

我的技术问题很容易解释.我想在我的DI中注册ILogger独立于正在调用的类T,但我需要从我的ILoggerFactory.CreateLogger<T>()方法中执行它,因为这将使用记录器配置Microsoft.Extensions.Configuration.

我需要使用这样的东西来实例我的记录器:

private Microsoft.Extensions.Logging.ILogger CreateLogger<T>()
{
     var factory = this.ResolveService<ILoggerFactory>();
     var logger = factory.CreateLogger<T>();
     return logger;
}
Run Code Online (Sandbox Code Playgroud)

我可以通过以下方式实现注射:

Container.Register(typeof(ILogger<>), typeof(Logger<>));
Run Code Online (Sandbox Code Playgroud)

这使我们可以解决类似的问题:

public class SomeApiController : ApiController
{
     public SomeApiController(ILogger<SomeApiController> logger)
     {
         //logger is well instantiated, but doesn't got the configuration
         logger.LogInformation("test log.");
     }
}
Run Code Online (Sandbox Code Playgroud)

但正如我所说,这样做不会通过从Microsoft.Extensions.Logging.ILoggerFactory类中获得的配置,所以这没用.

有没有办法ILogger<T>使用我的注册CreateLogger<T>

c# dependency-injection simple-injector ms-extensions-logging

12
推荐指数
2
解决办法
5291
查看次数

InvalidOperationException: Can't use schemaId .. 相同的 schemaId 已用于类型

我收到以下错误。

InvalidOperationException: Can't use schemaId "$Registration" for type "$PortalService.Models.Registration". The same schemaId is already used for type "$PortalService.Models.Registration"
Run Code Online (Sandbox Code Playgroud)

我已经尝试了以下链接中的建议,但没有成功。

招摇错误:冲突的schemaIds:检测到类型A和B的重复schemaIds

我在模型中只有一个注册类。我曾尝试重命名课程但没有成功。

我正在使用 OData .Net Core 3.1 项目。

配置 Swagger 如下

 services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
            services.AddSwaggerGen(c =>
            {
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Description = @"JWT Authorization header using the Bearer scheme. \r\n\r\n 
                      Enter 'Bearer' [space] and then your token in the text input below.
                      \r\n\r\nExample: 'Bearer 12345abcdef'",
                    Name = "Authorization",
                    In = ParameterLocation.Header,
                    Type = SecuritySchemeType.ApiKey,
                    Scheme = "Bearer"
                });

                c.AddSecurityRequirement(new OpenApiSecurityRequirement()
                  { …
Run Code Online (Sandbox Code Playgroud)

c# odata swagger asp.net-core-3.1

11
推荐指数
3
解决办法
9285
查看次数

.NET Framework MVC 和 Web Api Auth JWT

我在 MVC 中有一个项目,使用 .NET Framework v4.7 和一些 WebApi。我需要知道的是如何使用中间件来为 HTTP 请求和 MVC 操作请求授权 JWT。

我到处搜索以寻找解决方案示例,但找不到任何东西。

如果有人可以提供帮助,我将不胜感激。

对不起英语。

.net asp.net-mvc jwt asp.net-web-api2 bearer-token

10
推荐指数
1
解决办法
2711
查看次数

使用libCurl从gmail POP3帐户中读取电子邮件

我目前正在从事一个C++项目,该项目必须能够像gmail POP3帐户一样阅读电子邮件.同样重要的是,我需要下载邮件及其正文的附件(是编码base64?).事实是每个人都建议使用libCurl来完成这项任务,但是他们网站上的代码示例不起作用.我在Libcurl网站上看到了这个例子:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if(curl)
    {
         /* Set username and password */ 
         curl_easy_setopt(curl, CURLOPT_USERPWD, "user:password");

         /* This will only fetch the message with ID "1" of the given mailbox */ 
         curl_easy_setopt(curl, CURLOPT_URL, "pop3s://user@pop.example.com/1");

         /* Perform the request, res will get the return code */ 
         res = curl_easy_perform(curl);

         /* Check for errors */ 
         if(res != CURLE_OK)
         fprintf(stderr, "curl_easy_perform() failed: %s\n",
                curl_easy_strerror(res));

         /* always cleanup */ 
         curl_easy_cleanup(curl);
    } …
Run Code Online (Sandbox Code Playgroud)

c++ pop3 libcurl

8
推荐指数
1
解决办法
6505
查看次数

EF Core:方法“ProcessModelFinalized”没有实现

我在尝试使用实体框架核心获取 DbContext 对象中 DbSet 的信息时遇到错误。

我的 DbContext 对象看起来像这样:

public class CatalogueContext : DbContext
{
    public DbSet<ConnectorCatalogueItemConv> CatalogueItemConvs { get; set; }

    public CatalogueContext(DbContextOptions<CatalogueContext> options)
        : base(options)
    {

    }

    public CatalogueContext()
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

我试图通过调用一个接收泛型类型 T 的方法来实例化上下文,该类型可能是 DbContext 的子类:

public T GetContext<T>() where T: DbContext, new()
{
    var optionsBuilder = new DbContextOptionsBuilder<T>();
    var connectionString = Configuration.GetConnectionString(ExternalTablesKey);
    optionsBuilder.UseSqlServer(connectionString);
    return Activator.CreateInstance(typeof(T), optionsBuilder.Options) as T;
}
Run Code Online (Sandbox Code Playgroud)

通过使用 Microsoft.Extensions.Configuration 正确获取连接字符串,因此问题不存在。

最后,我调用此方法并尝试获取声明如下的 DbSet 上的任何记录:

 public void SomeMethod()
 {
     using (var db = this.GetContext<CatalogueContext>())
     {
         var val …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core asp.net-core

6
推荐指数
2
解决办法
3620
查看次数

如何在 ASP.NET Core 3.1 上运行的支持 OData 的 Web API 中添加 Swagger

我想在我的 Web API 中同时使用 OData 和 Swagger。我正在运行 ASP.NET Core 3.1。

我找到了这些文章,一篇启用 OData,另一篇启用 SwaggerUI

但是,我似乎无法同时启用两者。看来我把它们混合错了。

这是我目前拥有的代码:

启动.cs

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllers();
        services.AddOData();
        AddSwagger(services);
    }

    // This method gets called by the runtime. Use this method to configure the …
Run Code Online (Sandbox Code Playgroud)

c# odata swagger swashbuckle asp.net-core

6
推荐指数
2
解决办法
1万
查看次数

WPF:如何以不同的方向编写文本?

我需要按照下图所示的方向编写文本.事实是我在这里看到一些例子,使用文本块并使用"RenderTransform"旋转控件的角度,但这不是我真正需要的.我尝试使用图像来做它但它不太合适...所以我真的不知道如何解决它.如果您查看旁边的图像,您可以看到文本是从下到上书写的,文本下方的行位于屏幕右侧.这是我需要开发的屏幕:

我要做什么!

我尝试旋转文本块,但它对我有用的唯一方法是包装文本,但这只是我找到的"最接近"的解决方案.另外,如您所见,我需要为文本块设置边框.

在此输入图像描述

无论如何,我希望你能帮助我,因为周围的任何例子都符合我的问题.

wpf xaml textblock

5
推荐指数
1
解决办法
1941
查看次数

这个语法在抽象类的声明中意味着什么?

我想这是一个简单的问题,但我找不到正确的答案.这个语法是什么意思?我有点混淆行末的new():

public abstract class SomeClass<E> : Controller where E : ISomeInterface, new()
{
    //code of the abstract class
}
Run Code Online (Sandbox Code Playgroud)

c#

5
推荐指数
1
解决办法
121
查看次数

如何在 VS Code 中为 Cosmos DB 执行查询?

我已经安装了一个扩展,用于在 VS Code 中访问 Microsoft Azure Cosmos DB,并且我能够按预期查看其中的文档。

在此输入图像描述

但是,我无法弄清楚如何运行允许我根据不同条件过滤结果的查询,例如:SELECT * FROM c WHERE c.DocumentId = 123

有没有办法在 Cosmos DB 上的 VS Code 中运行 SQL 查询?我找不到任何有用的教程,并且通过安装“mssql”扩展似乎主要关注 ADO.NET 连接。

visual-studio-code azure-cosmosdb

4
推荐指数
1
解决办法
4888
查看次数

是否可以创建一个快捷方式来将未使用的用法删除到类中?

我经常尝试清理未使用的代码,原因可以通过这篇文章回答.

每当我想要这样做时,我必须使用我的鼠标,它可能有点烦人,所以这就是为什么我想在快捷方式中实现它.例如:

在此输入图像描述

这就是结果.

在此输入图像描述

我找不到任何相关的东西似乎有帮助.

c# visual-studio

3
推荐指数
1
解决办法
931
查看次数

如何在 OpenXML 中为格式为 (#,###.##) 的十进制创建 CellValue

我目前正在满足使用 Open XML 框架导出 Excel 文件的要求。我遇到的问题是,该电子表格的一列必须是十进制格式 (#,###.##),它必须允许求和。我可以使用以下方法以这种格式完美导出 Excel:

private static Cell CreateTextCell(string header, UInt32 index, object text, CellStyleIndex cellStyle)
{
    var cell = new Cell
    {
        DataType = CellValues.InlineString,
        CellReference = header + index,
        StyleIndex = (UInt32)cellStyle
    };

    var istring = new InlineString();
    var t = new Text { Text = text.ToString() };
    istring.AppendChild(t);
    cell.AppendChild(istring);
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

如您所见,我指定了应用我提到的格式的StyleIndex。但问题在于 Excel 将此值识别为文本:

在此处输入图片说明

这就是为什么我尝试创建一个新方法,该方法在我想在文件中创建小数时立即调用:

private static Cell CreateValueCell(string header, UInt32 index, decimal value, CellStyleIndex cellStyle)
{
     var cell = new …
Run Code Online (Sandbox Code Playgroud)

c# excel openxml

2
推荐指数
1
解决办法
9713
查看次数