小编mni*_*eto的帖子

使用 jsonpath 选择多个属性

我有一组像这样的对象:

[
    {
        "id": 192,
        "name": "Complete name",
        "username": "nsurname",
        "state": "active",
        "created_at": "2016-05-30T07:09:40.981Z",
        "organization": "",
        "last_sign_in_at": "2018-10-19T12:07:50.679Z",
        "confirmed_at": "2016-05-30T07:09:40.982Z",
        "last_activity_on": "2018-10-15",
        "email": "mail@myorganization.com",
        "current_sign_in_at": "2018-10-23T11:41:27.880Z",
        "identities": [
            {
                "provider": "ldapmain",
                "extern_uid": "user distinguished name"
            }
        ],
        "can_create_group": true,
        "can_create_project": false
    }
]
Run Code Online (Sandbox Code Playgroud)

我想要的是只提取属性的一个子集并得到如下内容:

[
   {
      "id" : 192,
      "name" : "complete name",
      "username" : "uname",
      "email" : "mail@myorganization.com",
      "extern_uid": "user distinguished name"
   }
]
Run Code Online (Sandbox Code Playgroud)

基于此答案,我使用http://jsonpath.herokuapp.com/ 上的Jayway JsonPath Evaluator 成功获得了带有此表达式的 id、name、username 和 email 属性

$..['id', 'name', …
Run Code Online (Sandbox Code Playgroud)

json jsonpath

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

EF 6 - 使用2个参数调用SetData的错误异常

我有一个包含多个项目的解决方案.DBContext文件和Models位于ClassLibrary项目中.这个项目有EF 6.1.3,它运行在.NET 4.5.2上.模型和DBContext文件采用不同的文件结构,我的意思是模型在Project/Data/Model中,而DBContext在Data文件夹中.此项目似乎已启用到现有数据库的迁移.开发团队过去只是通过构建项目来重新创建数据库.它也有:

AutomaticMigrationsEnabled = true;
Run Code Online (Sandbox Code Playgroud)

我正在尝试正确使用迁移,并尝试按照以下方式查看PackageManagerConsole正确反应.

Enable-Migrations
Add-Migration InitialCreate –IgnoreChanges
Run Code Online (Sandbox Code Playgroud)

两者都导致以下错误:

Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly  'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=14.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At C:\Users\Temp\.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:718 char:5
+     $domain.SetData('project', $project)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SerializationException   Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly  'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=14.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At C:\Users\Temp\.nuget\packages\EntityFramework\6.1.3\tools\EntityFramework.psm1:719 char:5
+     $domain.SetData('contextProject', $contextProject)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : …
Run Code Online (Sandbox Code Playgroud)

c# database ef-migrations entity-framework-6

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

LINQ包含多个孩子

我有一个存储数据库元数据的构造

public class Database {
    public string ConnectionString { get; set; }
    public virtual ICollection<Table> Tables { get; set; }
}

public class Table {
    public string TableName { get; set; }
    public virtual ICollection<ForeingKey> ForeingKeys { get; set; }
    public virtual ICollection<Field> Fields { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我想用LINQ检索一个唯一查询中的所有数据库相关数据我可以从数据库查询表和一个子实体

            var qry = from d in context.Databases
                         .Include(x => x.Tables.Select( c => c.Fields))
                      select d;
Run Code Online (Sandbox Code Playgroud)

但是,如何从Tables集合中读取两个孩子?像这样的东西

 var qry = from d in context.Databases
             .Include(x => x.Tables.Include(t => t.Fields).Include(t => t.ForeingKeys)) …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework

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

serilog格式SourceContext,仅显示程序集名称

我将我的项目配置为使用Serilog使用依赖注入进行日志记录.我在类构造函数中使用以下模式:

namespace FlickPopper.API.Controllers {

    public class ValuesController : Controller {
        private ILogger<ValuesController> _logger;
        public MyClass(ILogger<ValuesController> logger) {
           _logger = logger;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

通过这种方式,serilog创建了记录器调用 Log.ForContext<classname>

我的设置是:

  "Serilog": {
      "WriteTo": [
        {
          "Name": "RollingFile",
          "Args": {
            "pathFormat": "Logs\\log-{Date}.txt",
            "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] [{SourceContext}] {Message}{NewLine}{Exception}"
          }
        }
      ],
      "Enrich": [ "FromLogContext" ]
    }
Run Code Online (Sandbox Code Playgroud)

所以,日志看起来像这样:

2018-01-26 22:20:08 [INF] [FlickPopper.API.Controllers.ValuesController] Get all values
Run Code Online (Sandbox Code Playgroud)

格式化SourceContext属性以仅显示日志中的程序集名称,这是什么方式?

2018-01-26 22:20:08 [INF] [FlickPopper.API] Get all values
Run Code Online (Sandbox Code Playgroud)

c# serilog .net-core asp.net-core-2.0

4
推荐指数
2
解决办法
2317
查看次数

具有null属性的select-object -expandproperty

我有一组对象,其中包含id,username,email,current_sign_in_at,identityities等属性.其中Identities属性是具有两个属性的对象数组.这将是对象的json表示:

{
        "id": 45,
        "name": "Emilio Roche",
        "username": "EROCHE",
        "state": "active",
        "identities": [
            {
                "provider": "ldapmain",
                "extern_uid": "cn=roche\\, emilio,ou=xxxxxxxxxx"
            }    
          ]
    }
Run Code Online (Sandbox Code Playgroud)

但是列表中的一些元素没有identityities属性.所以,当我这样做时:

Get-Collection | Select-Object id, username  -ExpandProperty identities
Run Code Online (Sandbox Code Playgroud)

我只获得具有identities属性的元素.我需要所有实体,有或没有身份属性

powershell select-object

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