小编Kra*_*zek的帖子

实体框架4 - 在持久性不知情的上下文中使用CTP5(代码优先)映射非公共属性

我知道这个问题已经有了解决方案(例如这个问题),但是我真的无法将映射逻辑附加到域(POCO类)所在的同一个程序集中.

还有其他方法吗?

我找到了这篇不错的博文,但我无法让它发挥作用.这是模型:

public class Institute
{
    /**
        Code omitted
    **/

    protected virtual ICollection<InstituteText> InnerInstituteTexts { get; set; }

    private InstituteTextSet _TextSets;

    public InstituteTextSet Texts 
    {
        get 
        {
            if (_TextSets == null)
                _TextSets = new InstituteTextSet(InnerInstituteTexts);

            return _TextSets;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

映射代码:

var instituteTextExpression = ObjectAccessor<Institute>.CreateExpression<ICollection<InstituteText>>("InnerInstituteTexts");

institute.HasMany(instituteTextExpression)
    .WithRequired()
    .HasForeignKey(t => t.InstituteId);
Run Code Online (Sandbox Code Playgroud)

其中CreateExpression定义为:

public static Expression<Func<T, TResult>> CreateExpression<TResult>(string propertyOrFieldName)
{
    ParameterExpression param = Expression.Parameter(typeof(T), "propertyOrFieldContainer");
    Expression body = Expression.PropertyOrField(param, propertyOrFieldName);
    LambdaExpression lambda = Expression.Lambda(typeof(Func<T, TResult>), body, param); …
Run Code Online (Sandbox Code Playgroud)

code-first entity-framework-4 ef-code-first entity-framework-ctp5 entity-framework-4.1

12
推荐指数
1
解决办法
2608
查看次数

无法还原ASP.NET Core 1.0 RTM解决方案

我刚刚将一个正在运行的RC2 Web应用程序转换为RTM,我在IIS上发布了一些问题.

我找到的所有示例都基于NetCoreApp1.0应用程序.由于某些要求,我们仅限于"net46".

这是project.json

{
  "version": "1.0.0-*",
  "dependencies": {
    "Domain": "1.0.0-*",
    "Microsoft.AspNetCore.Authentication": "1.0.0",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Authentication.Facebook": "1.0.0",
    "Microsoft.AspNetCore.DataProtection.SystemWeb": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Http.Extensions": "1.0.0",
    "Microsoft.AspNetCore.Localization": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "PublicLib": "1.0.0-*",
    "PublicLib.Imaging": "1.0.0-*",
    "PublicLib.Interfaces": "1.0.0-*",
    "Storage": "1.0.0-*"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview2-final"
    }
  },

  "frameworks": {
    "net46": {

    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "publishOptions": {
    "include": [
      "wwwroot", …
Run Code Online (Sandbox Code Playgroud)

c# asp.net iis project.json asp.net-core-1.0

9
推荐指数
2
解决办法
2980
查看次数

如何对自定义 JsonConverter 进行单元测试

我有一个 json 有效负载,我想以一种非平凡的方式反序列化。

{
   "destinationId": 123
}
Run Code Online (Sandbox Code Playgroud)

目标类是

public class SomeObject
{
    public Destination Destination { get; set; }
}

public class Destination
{
    public Destination(int destinationId)
    {
        Id = destinationId;
    }

    public int Id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

为了能够做到这一点,我创建了一个JsonConverter照顾它的人。

这是 ReadJson 方法:

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
    if (CanConvert(objectType))
    {
        var value = reader.Value;

        if (value is long v)
        {
            // TODO: this might overflow
            return new Destination((int)v);
        } …
Run Code Online (Sandbox Code Playgroud)

.net c# nunit unit-testing json.net

9
推荐指数
1
解决办法
4575
查看次数

跳过TeamCity中个人构建的步骤

在运行TeamCity 8.0的CI服务器上,我有一个构建配置,其最后一步是创建和推送新版本的NuGet包.

我想知道如果当前版本是个人版本,是否有办法抑制这两个步骤.

任何线索?

teamcity teamcity-8.0

7
推荐指数
2
解决办法
3176
查看次数

如何将一个巨大的解决方案分成更小的部分

在我的日常工作解决方案中,我们有大约80个项目.此解决方案包含4个不同的Web站点,业务逻辑和基础架构程序集(如扩展方法,各种实用程序,存储库基类等).

该解决方案非常有效,但如果我们将测试项目添加到解决方案中,我们可以轻松地通过100个项目,这使得使用此解决方案非常繁琐.

在我寻找解决方案时,我对Nuget非常感兴趣,我开始怀疑它是否可以帮助我们.

我们的想法是将巨大的解决方案分成更小的原子片,其输出将是一个Nuget包,可以上传到私有Nuget存储库.

Web站点将引用除绑定到该特定Web站点的类库之外的包.

从CI的角度来看:

每个包解决方案应该是原子的.

  • 它应该能够获取它的引用(其他NuGet包,来自官方提要和私有包);
  • 建立
  • 运行它的测试
  • 组装包
  • 将新包上载到存储库

产品解决方案(比如网站)应该在以下情况下构建:

  • 提交他们的代码
  • 私有存储库上的NuGet包的更新

有什么建议吗?或者可能是实现这个巨大解决方案分裂的更好方法?

.net continuous-integration nuget

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

创建表达式树,为Entity Framework生成参数查询

我正在尝试创建一个用于组成Entity Framework(5)查询的泛型类.

我让它工作,唯一的问题是值被注入作为查询的常量而不是作为参数.这减少了EF缓存查询并在以后重用它的可能性.

这是我到目前为止所得到的.

public class MinDateFilter<T> : IFilter<T> where T : class
{
    private readonly Expression<Func<T, bool>> _predicate;

    public MinDateCandidateFilter(Expression<Func<T, DateTime>> propertySelector, DateTime from)
    {
        from = from.Date.AddDays(-1);
        from = new DateTime(from.Year, from.Month, from.Day, 23, 59, 59, 999);

        Expression value = Expression.Constant(from, typeof(DateTime));
        //ParameterExpression variable = Expression.Variable(typeof(DateTime), "value");

        MemberExpression memberExpression = (MemberExpression)propertySelector.Body;
        ParameterExpression parameter = Expression.Parameter(typeof(T), "item");
        Expression exp = Expression.MakeMemberAccess(parameter, memberExpression.Member);

        Expression operation = Expression.GreaterThan(exp, value);
        //Expression operation = Expression.GreaterThan(exp, variable);
        _predicate = Expression.Lambda<Func<T, bool>>(operation, parameter);
    }

    public …
Run Code Online (Sandbox Code Playgroud)

entity-framework expression-trees

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

AWS ALB 从 Lambda 返回 502 而不是自定义 HTTP 状态

我创建了一个 Lambda,它检查 DynamoDB 表是否存在匹配主机和请求路径的记录,如果找到,则返回到匹配 URL 的重定向。

我的 Lambda 返回此响应,但 ALB 返回 502。

{
    "statusCode": 301,
    "statusDescription": null,
    "headers": {
        "Location": "https://www.my-target.co.uk/"
    },
    "multiValueHeaders": null,
    "body": "Redirecting to https://www.my-target.co.uk/",
    "isBase64Encoded": false
}
Run Code Online (Sandbox Code Playgroud)

这是我在 CloudWatch 中为 Lambda 函数找到的日志

START RequestId: 8b5a28f2-c56d-4418-a7b9-66ebe0ba2470 Version: $LATEST
[Information] EMG.ApplicationLoadBalancerRequestHandler: Received: GET / 
[Information] EMG.ApplicationLoadBalancerRequestHandler: Processing: my-test.net / 
[Information] EMG.RedirectManagers.RedirectTableRedirectManager: Fetching item: my-test.net / from table redirect-table 
[Information] EMG.ApplicationLoadBalancerRequestHandler: Found: https://www.target.co.uk/ Permanent 
END RequestId: 8b5a28f2-c56d-4418-a7b9-66ebe0ba2470
REPORT RequestId: 8b5a28f2-c56d-4418-a7b9-66ebe0ba2470  Duration: 69.59 ms  Billed Duration: 100 ms Memory Size: …
Run Code Online (Sandbox Code Playgroud)

aws-lambda aws-application-load-balancer

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

将表达式树从类型转换为具有复杂映射的另一种类型

这个答案的启发我试图将模型类的属性映射到基于实际实体的表达式.这是涉及的两个类:

public class Customer
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Id { get; set; }
    public DateTime? BirthDate { get; set; }
    public int CustomerTypeId { get; set; }
}

public class CustomerModel
{
    ...
    public bool HasEvenId { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我想要转换的可能表达式的示例是:

Expression<Func<CustomerModel, bool>> from = model => model.HasEvenId;
Expression<Func<Customer, bool>> to = entity => ((entity.Id % 2) == 0);
Run Code Online (Sandbox Code Playgroud)

问题是我必须通过ASP.NET WebAPI公开OData端点,但是我需要先对实体进行一些操作,因此需要一个模型类,需要根据模型转换表达式我可以在基于实体的表达式中接收OData查询,我将用它来查询EF4.

这是我到目前为止的地方:

private static …
Run Code Online (Sandbox Code Playgroud)

linq entity-framework expression-trees asp.net-web-api

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

使用 Moq 测试接受委托的方法

我的代码正在使用一个实现这样的接口的组件

public interface IFoo 
{ 
    void DoSomething(string p1);

    void DoSomething(string p1, Action<string> p2);
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我正在使用第一种方法,但我计划转向第二种方法,我希望尽可能保持高覆盖率。

只是我真的不知道如何检查委托,甚至不知道如何设置 Moq 来模拟界面。

我试过

mock.Setup(p => p.DoSomething(It.IsAny<string>(), It.IsAny<Delegate>()));
mock.Setup(p => p.DoSomething(It.IsAny<string>(), It.IsAny<Action<string>>()));
Run Code Online (Sandbox Code Playgroud)

但也不会让我建造。有什么建议吗?

c# delegates unit-testing moq

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

语法高亮部分在 VS Code for C# 上工作

我有一台笔记本电脑和一台电脑。两者都安装了相同版本的 Visual Studio Code。

笔记本电脑以这种方式显示 C# 文件:

http://imgur.com/OHn5w1o

pc 以另一种方式显示相同的 C# 文件:

在此处输入图片说明

显然,我更喜欢笔记本电脑版本。但是我无法让 PC 以相同的方式为文本着色。

有什么建议吗?

c# syntax-highlighting visual-studio-code vscode-settings

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

如何将不同的Powershell宏合并为一个?

由于.NET Core已经出局,我一直在使用越来越多的命令行作为工作方式,一般来说我使用了很多PowerShell.

虽然Visual Studio Code非常符合命令行,但对于它的大哥来说却不能说是相同的.

为了改善这种情况,我在$ PROFILE文件中添加了以下内容.

function Execute-VisualStudioAsAdmin
{
    if ($args.Count -gt 0)
    {
        Start-Process "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe" $args -Verb RunAs
    }
    else
    {
        Start-Process "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe" -Verb RunAs
    }
}

Set-Alias vsa Execute-VisualStudioAsAdmin -Option ReadOnly

Set-Alias vs "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe" -Option ReadOnly
Run Code Online (Sandbox Code Playgroud)

现在我能做到

PS> vs

PS> vsa

PS> vs .\Solution.sln

PS> vsa .\Solution.sln
Run Code Online (Sandbox Code Playgroud)

一切都按预期工作,但它不如我想的那么好.也许我正在考虑它,但我想知道是否有办法创建一个更好的功能,并通过传递不同的参数使用它的两个别名.

提前致谢!

powershell

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