小编Snæ*_*ørn的帖子

在继承的类上多次定义接口

我基本上IFoo在Inherited类中定义了两次.这是否会导致一些不可预见的后果?

interface IFoo {
   ...
}

interface IBar : IFoo {
   ...
}

class Base : IFoo {
   ...
}

class Derived : Base, IBar {
   ...
}
Run Code Online (Sandbox Code Playgroud)

我想打的原因IBar继承IFoo的,所以我可以工作Derived,因为它是IFoo无需进行转换的.

if (Derived is IBar)
   // Do work
Run Code Online (Sandbox Code Playgroud)

如果它不继承我必须施放它.这使得使用更复杂,并且类的用户可能不理解那IBar只是一个专业化IFoo.

if (Derived is IBar)
   Derived as IFoo
   // Do work
Run Code Online (Sandbox Code Playgroud)

这是不好的做法吗?这个问题有什么其他解决方案?

c# inheritance interface

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

如何在MySql Connector 6.9.6中设置SetSqlGenerator和CodeGenerator?

我将我的MySql连接器/ net更新为6.9.6(从6.9.5)和EF更新到6.1.3(从6.1.2),这破坏了迁移:(

我曾经有过这个,这将使迁移在MySql上运行.

public Configuration()
{
    // fails with cannot assign MySqlMigrationSqlGenerator toSystem.Data.Entity.Migrations.Sql.MigrationSqlGenerator
    SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());

    // fails with cannot assign MySqlMigrationCodeGenerator to System.Data.Entity.Migrations.Design.MigrationCodeGenerator
    CodeGenerator = new MySql.Data.Entity.MySqlMigrationCodeGenerator();
}
Run Code Online (Sandbox Code Playgroud)

但现在这不起作用.当我删除它时,生成的迁移前缀dbo不起作用.

我尝试在web.config中设置配置

<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
Run Code Online (Sandbox Code Playgroud)

还尝试在上下文中设置属性.

[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class MyContext : DbContext
Run Code Online (Sandbox Code Playgroud)

但无济于事.

如何使用此新连接器重新启动迁移?

mysql ef-migrations entity-framework-6

5
推荐指数
0
解决办法
1673
查看次数

使用GROUP BY和COUNT优化/重写LINQ查询

我正在尝试按以下数据集计算按名称分组的唯一Foos和Bars.

Id  |   IsActive    |   Name    |   Foo     |   Bar
1   |       1       |   A       |   11      |   null
2   |       1       |   A       |   11      |   null
3   |       1       |   A       |   null    |   123
4   |       1       |   B       |   null    |   321
Run Code Online (Sandbox Code Playgroud)

我希望上面数据的结果是:

Expected:
A = 2;
B = 1;
Run Code Online (Sandbox Code Playgroud)

我尝试按名称,Foo,Bar进行分组,然后再按名称分组,并使用计数来获取"行"计数.但那并没有给我正确的结果.(或者ToDictionary扔了一个重复的键,我玩了很多,所以不记得了)

db.MyEntity
    .Where(x => x.IsActive)
    .GroupBy(x => new { x.Name, x.Foo, x.Bar })
    .GroupBy(x => new { x.Key.Name, Count = x.Count() })
    .ToDictionary(x => x.Key, x …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

更新到ASP NET 5 beta5打破了一切

我在更新到beta5时遵循了本指南,并且更新过程似乎有效.

http://blogs.msdn.com/b/webdev/archive/2015/06/30/asp-net-5-beta5-now-available.aspx

要更新到ASP.NET 5 Beta5,请使用以下步骤:

  • 如果您还没有安装.NET版本管理器(DNVM)(它预装了Visual Studio 2015 RC,或者您可以获得最新版本)
  • 从命令提示符处将DNX_FEED环境变量设置为https://www.nuget.org/api/v2
  • 运行"dnvm upgrade"在您的应用程序中更新您的global.json以指向beta5版本的.NET执行环境(DNX)
  • 你的project.json也指向beta5包版本
  • 运行"dnu restore"运行"dnu build"并将代码迁移到需要的beta5

但是我遇到构建错误,说我丢失了程序集.它抱怨System.Void,这样就丢失了.它也找不到来自Microsoft.AspNet.MVC的Controller:/

如果我恢复到beta4然后再次工作.

我错过了什么步骤?

DNVM列表(这将恢复为beta4)

Active Version           Runtime Architecture Location                      Ali
                                                                            as
------ -------           ------- ------------ --------                      ---
       1.0.0-beta4       clr     x64          C:\Users\MySelf\.dnx\runtimes
  *    1.0.0-beta4       clr     x86          C:\Users\MySelf\.dnx\runtimes
       1.0.0-beta4       coreclr x64          C:\Users\MySelf\.dnx\runtimes
       1.0.0-beta4       coreclr x86          C:\Users\MySelf\.dnx\runtimes
       1.0.0-beta5       clr     x86          C:\Users\Myself\.dnx\runtimes def
       1.0.0-beta5-12103 clr     x86          C:\Users\MySelf\.dnx\runtimes
Run Code Online (Sandbox Code Playgroud)

c# dnx dnvm asp.net-core

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

Visual Studio 2015的代码/分支覆盖工具

我正在寻找在Visual Studio 2015社区版中获得代码覆盖率的方法.我无法找到VS2013的免费工具,所以想知道在VS2015中是否发生了新的事情.

我目前正在使用OpenCover,但这并没有为我的代码着色.或者我无法弄明白.

在此输入图像描述

如果没有免费工具,那么最好的付费工具是什么?任何免费的开源项目?

nunit code-coverage xunit.net opencover visual-studio-2015

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

在异常时重新排队消息

我正在寻找一种可靠的方法来重新排队无法正确处理的消息 - 目前.

我一直在关注http://dotnetcodr.com/2014/06/16/rabbitmq-in-net-c-basic-error-handling-in-receiver/,似乎支持在RabbitMQ中重新排队消息API.

else //reject the message but push back to queue for later re-try
{
    Console.WriteLine("Rejecting message and putting it back to the queue: {0}", message);
    model.BasicReject(deliveryArguments.DeliveryTag, true);
}
Run Code Online (Sandbox Code Playgroud)

但是我正在使用EasyNetQ.所以想知道我将如何做类似的事情.

bus.Subscribe<MyMessage>("my_subscription_id", msg => {
    try
    {
        // do work... could be long running
    }
    catch ()
    {
        // something went wrong - requeue message
    }
});
Run Code Online (Sandbox Code Playgroud)

这甚至是一个好方法吗?不ACK,如果该消息可能导致的问题do work超过了等待ACK由RabbitMQ的服务器超时.

c# publish-subscribe rabbitmq easynetq

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

如何在管道中连接数组

我希望加入管道的结果.

我试过用 -join

PS> type .\bleh.log | where { $_ -match "foo"} | select -uniq | $_ -join ','
Run Code Online (Sandbox Code Playgroud)

但那给了我这个错误:/

表达式仅允许作为管道的第一个元素.

powershell join pipe

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

Swagger可以呈现app.UseDeveloperExceptionPage()的内容吗?

我有一个ASP.NET Core 2.0 Web API,通过Swashbuckle在其中添加了Swagger。很好

我还在app.UseDeveloperExceptionPage()ASP.NET Core中启用了该选项。很好

但是他们在一起玩的不好。因为SwaggerUI只是将返回的HTML显示为文本。

对于GET请求,这不是一个大问题,因为我只是将URL粘贴到浏览器中。但是对于POST不起作用。所以我想知道是否有一种方法可以使SwaggerUI在Content-Type标头为时呈现html text/html。我一直找不到与此相关的任何东西,这有点令人困惑:)

swagger swagger-ui swashbuckle asp.net-core

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

在Gradle Spring Boot Hibernate项目中设置LiquiBase

我在Spring Boot项目中很难设置LiquiBase。我试图浏览文档并找到一些指南-但它们似乎彼此矛盾:(

我希望通过Gradle使用LiquiBase,并且希望它从Hibernate生成变更日志,并最终获得一个SQL脚本,我可以在服务器上运行该脚本以将架构更新为适当的版本。

为了使其通过Gradle运行,我使用了此插件 https://github.com/liquibase/liquibase-gradle-plugin,并使用了自述文件中显示的推荐设置。

为了使Hibernate diff能够正常工作,我正在使用https://github.com/liquibase/liquibase-hibernate

这是我的build.gradle文件:

buildscript {
    ext {
        springBootVersion = '2.0.5.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

plugins {
    id 'java'
    id 'net.ltgt.apt' version '0.10' // https://projectlombok.org/setup/gradle
    id 'org.liquibase.gradle' version '2.0.1' // https://github.com/liquibase/liquibase-gradle-plugin
}

apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()

    maven {
        credentials {
            username = oracleUser
            password = oraclePass …
Run Code Online (Sandbox Code Playgroud)

java hibernate liquibase gradle spring-boot

5
推荐指数
2
解决办法
3185
查看次数

IronPDF 并行运行时出现死锁

我正在尝试使用 IronPDFs HTML 到 PDF 功能并行生成多个 PDF。但从 ASP.NET 启动时似乎陷入僵局:(

我在这里重新创建了问题:https ://github.com/snebjorn/ironpdf-threading-issue-aspnet

这是包含基本部分的片段。

打电话GetSequential()有效。但不是并行执行。 GetSimple()并行运行但出现死锁。

public class TestController : Controller
{
    [HttpGet]
    [Route("simple")]
    public async Task<IActionResult> GetSimple()
    {
        var tasks = Enumerable
            .Range(1, 10)
            .Select(i => HtmlToDocumentAsync("hello", i));
        var pdfs = await Task.WhenAll(tasks);

        using var pdf = PdfDocument.Merge(pdfs);
        pdf.SaveAs("output.pdf");
        return Ok();
    }

    [HttpGet]
    [Route("seq")]
    public async Task<IActionResult> GetSequential()
    {
        var pdfs = new List<PdfDocument>();
        foreach (var i in Enumerable.Range(1, 10))
        {
            pdfs.Add(await HtmlToDocumentAsync("hello", i));
        }

        using var …
Run Code Online (Sandbox Code Playgroud)

c# parallel-processing async-await asp.net-core ironpdf

5
推荐指数
2
解决办法
2062
查看次数