小编gme*_*rio的帖子

XPath仅在直接子节点中选择一种类型的节点

也许有人可以帮我找到问题的解决方案.我需要在下面的xml中执行XPath查询,该查询仅提取作为直接子节点的"Field"节点.在下面的示例中,查询应该拉取字段E1F1,E1F2和E1F3.到目前为止,我正在运行查询://Field但是我得到了所有字段(包括属于E1_1的字段,我不想要).

<Entity id="E1">
  <Field id="E1F1"></Field>
  <Field id="E1F2"></Field>
  <Field id="E1F3"></Field>
  <Entity id="E1_1">
    <Field id="E1_1F1"></Field>
    <Field id="E1_1F2"></Field>
    <Field id="E1_1F3"></Field>
  </Entity>
Run Code Online (Sandbox Code Playgroud)

谢谢!!

xpath

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

Angular指令使用Typescript接收对象作为属性

我正在开发使用Angular 1.5.8和Typescript我有一个指令,它在另一个指令(当然是另一个控制器)的范围内使用.让我们说Directive1,Controller1和Directive2,Controller2.鉴于Controller1已经拥有用户信息,我想通过Directive2将此用户信息传递给Controller2,以防止再次从后端获取信息.我不确定这是否可以做到,但如果是这样的话会很好:)

以下是帮助我解释的代码:

Directive1 HTML:

<div>
    ...
    <directive2 user="{{ctrl.loggedUser}}"></directive2>
    ...
</div>
Run Code Online (Sandbox Code Playgroud)

loggedUser通过对后端的调用加载到Controller1构造函数中.

Directive2和Directive2Ctrl Typescript代码:

class Directive2 implements ng.IDirective {
    controller = "Directive2Ctrl";
    controllerAs = "d2Ctrl";
    bindToController = {
        user: "@"
    };
    restrict = "E";
    templateUrl = "directive2.html";

    static factory(): ng.IDirectiveFactory {
        const directive = () => new Directive2();
        return directive;
    }
}
angular
    .module("app")
    .controller("Directive2Ctrl", Directive2Ctrl)
    .directive("directive2", Directive2.factory());


class Directive2Ctrl implements IDirective2Ctrl {
    public user: User;

    constructor(user: User) {
         // user is undefined
    }

    $onInit(user: User): void {
        // user …
Run Code Online (Sandbox Code Playgroud)

angularjs typescript angularjs-directive typescript1.8

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

实体框架通用存储库,包括通过参数的属性

我在实体框架中有一个通用存储库的实现,我正在尝试改进它以使用 EF 提供的 .Include(..) 函数,而不是通过字符串包含导航属性,以便能够安全地重命名属性。

下面是我当前的代码:

public IQueryable<T> GetAll(
        Expression<Func<T, bool>> filter = null,
        Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null,
        string includeProperties = "")
    {
        IQueryable<T> query = dbSet;

        if (filter != null)
        {
            query = query.Where(filter);
        }

        foreach (var includeProperty in includeProperties.Split
            (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
        {
            query = query.Include(includeProperty);
        }

        if (orderBy != null)
        {
            return orderBy(query);
        }
        else
        {
            return query;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我目前通过以下方式使用它:

repository.GetAll(
    u => u.Name = "John",
    u => u.OrderBy(x => x.Name),
    "Address.State", …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework .net-core

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