小编Dav*_*eny的帖子

使用Dapper从数据库中检索XML

我正在使用Dapper查询包含XML字段的表:

CREATE TABLE Workflow
(
    Guid uniqueidentifier not null,
    State xml not null
)
Run Code Online (Sandbox Code Playgroud)

然后将其映射到XDocument类型的属性:

public class Workflow
{
    public Guid InstanceId { get;set; }
    public XDocument State { get;set; }
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试查询表时,我收到以下错误:

Error parsing column 1 (State= - String)
   at Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader, Object value) in d:\\Dev\\dapper-dot-net\\Dapper NET40\\SqlMapper.cs:line 4045
   at Deserialize038b29f4-d97d-4b62-b45b-786bd7d50e7a(IDataReader )
   at Dapper.SqlMapper.<QueryImpl>d__11`1.MoveNext() in d:\\Dev\\dapper-dot-net\\Dapper NET40\\SqlMapper.cs:line 1572
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 …
Run Code Online (Sandbox Code Playgroud)

dapper

7
推荐指数
1
解决办法
3635
查看次数

为什么Type.GetType()工作而Assembly.GetType()不起作用?

我试图从程序集列表中找到运行时的类型; 我的代码是这样的:

foreach (Assembly assembly in assembliesToSearch)
{
    Type t = assembly.GetType(assemblyName);
    if (t != null)
    {
        return t;
    }
}
Run Code Online (Sandbox Code Playgroud)

,我遇到的问题是t总是出现为null.在VS2010中使用调试器和中间窗口,我在循环中放置一个断点时注意到以下内容:

Type.GetType(typeof(MyNamespace.MyClass).AssemblyQualifiedName)
Run Code Online (Sandbox Code Playgroud)

工作正常,但是

assembly.GetType(typeof(MyNamespace.MyClass).AssemblyQualifiedName)
Run Code Online (Sandbox Code Playgroud)

没有(当程序集是我知道包含我正在寻找的类的程序集 - 在调试器中,我可以在assembly.GetTypes()上查看,浏览到我试图实例化的类,并调用程序集.GetType("MyNamespace.MyClass,MyNamespace")).

有谁知道为什么使用Type.GetType()搜索所有程序集,但搜索我知道的程序集包含使用assembly.GetType()的类型不起作用?

c# reflection

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

WiX无法正确渲染图像

我正在尝试编写一个自定义WiX对话框,作为其工作流程的一部分,它会显示错误图像以响应某些条件.然而,WiX似乎忽略了我的尺寸并显示它感觉合适.这是我的代码:

<Binary Id="WixUI_FailureImg" SourceFile="$(sys.SOURCEFILEDIR)..\Resources\Failure.ico" />
<Control Id="TestResult_Failure" Type="Icon" IconSize="16" X="15" Y="206" Width="16" Height="16" Text="WixUI_FailureImg">
    <Condition Action="hide">LOGON_VALID = "1"</Condition>
    <Condition Action="show">LOGON_VALID = "0"</Condition>
</Control>
Run Code Online (Sandbox Code Playgroud)

我在下面包含了一个结果对话框的片段,背景中包含原始图像(16x16 .ico).如您所见,图像已向上缩放,图像周围没有透明度.我已经尝试了8位和24位位图以及图标,但它们都产生相同的结果.我做的事情显然是错的吗?

borked图像的例子

更新:

如果您想知道动态图像的工作原理,请参阅相关章节:

<Control Id="TestResult_Success" Type="Icon" IconSize="16" X="15" Y="210" Width="12" Height="12" Text="WixUI_SuccessImg">
    <Condition Action="hide">LOGON_VALID = "0"</Condition>
    <Condition Action="show">LOGON_VALID = "1"</Condition>
</Control>
<Control Id="TestPrompt_Success" Type="Text" X="35" Y="210" Width="322" Height="10" Text="!(loc.SqlSelectDlgConnectionValid)">
    <Condition Action="hide">LOGON_VALID = "0"</Condition>
    <Condition Action="show">LOGON_VALID = "1"</Condition>
</Control>
<Control Id="TestResult_Failure" Type="Icon" IconSize="16" X="15" Y="210" Width="12" Height="12" Text="WixUI_FailureImg">
    <Condition Action="hide">LOGON_VALID = "1"</Condition>
    <Condition Action="show">LOGON_VALID = "0"</Condition>
</Control> …
Run Code Online (Sandbox Code Playgroud)

wix bitmap wix3.5

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

如何从ModelMetadata检索GroupName数据注释

System.ComponentModel.DataAnnotations中的DisplayAttribute具有GroupName属性,该属性允许您在UI控件(例如WPF/WinForms中的属性网格)中逻辑地将字段组合在一起.

我试图在ASP.NET MVC3应用程序中访问此元数据,主要是为了创建属性网格.如果我的模型看起来像这样:

public class Customer
{
    [ReadOnly]
    public int Id { get;set; }

    [Display(Name = "Name", Description = "Customer's name", GroupName = "Basic")]
    [Required(ErrorMessage = "Please enter the customer's name")]
    [StringLength(255)]
    public string Name { get;set; }

    [Display(Name = "Email", Description = "Customer's primary email address", GroupName = "Basic")]
    [Required]
    [StringLength(255)]
    [DataType(DataType.Email)]
    public string EmailAddress { get;set; }

    [Display(Name = "Last Order", Description = "The date when the customer last placed an order", GroupName = "Status")]
    public DateTime LastOrderPlaced …
Run Code Online (Sandbox Code Playgroud)

data-annotations asp.net-mvc-3

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

未找到WebApi控制器测试方法

我有一个在.NET Framework 4.6.2上运行的非常简单的WebAPI 2控制器,如下所示:

[RoutePrefix("Invitations")]
public class InvitationsController : CqrsApiController
{
    [HttpPost, Route("Clients/{id:long}/Actions/Cancel")]
    public IHttpActionResult PostClientInvitationCancel(long id, [FromBody] ClientInvitationCancelCommand command)
    {
        Execute(command);
        return SeeOther("Invitations/Clients/{0}", id);
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试为它编写NUnit测试,如下所示:

[TestFixture]
public class WhenExecutingAValidCommand
{
    [Test]
    public void ItShouldReturnARedirect()
    {
        var dispatcher = Substitute.For<ICqrsDispatcher>();
        var urlHelper = Substitute.For<UrlHelper>();
        urlHelper.Link(Arg.Any<string>(), Arg.Any<object>()).Returns("https://tempuri.org/");

        var sut = new InvitationsController(dispatcher);
        sut.Request = new HttpRequestMessage();
        sut.Configuration = new HttpConfiguration();
        sut.Url = urlHelper;

        var response = sut.PostClientInvitationCancel(1, new ClientInvitationCancelCommand());
        response.Should().BeOfType<SeeOtherRedirectResult>();
    }
}
Run Code Online (Sandbox Code Playgroud)

```

但是,当我运行测试时,我收到以下错误:

System.MissingMethodException : Method not found: …
Run Code Online (Sandbox Code Playgroud)

c# testing asp.net-web-api2

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

如何在不使用触发器的情况下将管道限制到特定分支?

如何限制 Azure DevOps 中的按需(即不触发)管道,使其仅在特定分支上运行?

例如,我有一个管道(使用较新的 YAML 语法),它只能在分支上运行master,因为它用于将代码推送到生产环境,并且只能由某些开发人员运行(我们处理大量 PII 数据,因此我们的审计控制要求相当高)。我有另一个管道,应该在除 之外的 master任何分支上运行,因为它用于将代码推送到集成/测试环境,并且可以由任何人运行。

如果我指定了一个触发器,我可以告诉它只在某些分支上触发;但如果我trigger: none在 YAML 中设置,则无法应用这些限制。有任何想法吗?

azure-devops

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

Web API请求内容为空

我有一个DelegatingHandler实现来记录请求/响应内容:

public class RequestAndResponseLoggerDelegatingHandler : DelegatingHandler
{
    public IDataAccess Data { get; set; }

    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        var started = DateTime.UtcNow;
        var response = await base.SendAsync(request, cancellationToken);
        await Log(started, request, response);
        return response;
    }

    private async Task Log(DateTime start, HttpRequestMessage request, HttpResponseMessage response)
    {
        var finished = DateTime.UtcNow;
        var requestContent = await request.Content.ReadAsStringAsync();
        var responseContent = await response.Content.ReadAsStringAsync();
        var info = new ApiLogEntry(start, finished, requestContent, responseContent, request, response);
        Data.Log(info);
    }
}
Run Code Online (Sandbox Code Playgroud)

但出于某种原因requestContent,空洞来了. …

c# async-await asp.net-web-api

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

Does Dapper support custom types on stored procedure parameters?

If I have a custom type (in my case, a Date class), is it possible to have Dapper automatically handle the type conversions when setting up stored procedure parameters? At the moment, I have to do this:

public void Execute(Date value)
{
    var parameters = new DynamicParameters();
    parameters.Add("MyDate", Date.ToDateTime(), DbType.Date);
    Execute("dbo.InsertDate", parameters, CommandType.StoredProcedure);
}
Run Code Online (Sandbox Code Playgroud)

Do I really have to convert it to a more recognised system type? I was hoping that Dapper's TypeHandler code would work, but it seems to …

c# dapper

-1
推荐指数
1
解决办法
77
查看次数