小编Pet*_*ony的帖子

修改 IQueryable.Include() 的表达式树以向连接添加条件

基本上,我想实现一个存储库,即使通过导航属性也可以过滤所有软删除记录。所以我有一个基本实体,类似这样:

public abstract class Entity
{
    public int Id { get; set; }

    public bool IsDeleted { get; set; }

    ...
}
Run Code Online (Sandbox Code Playgroud)

和一个存储库:

public class BaseStore<TEntity> : IStore<TEntity> where TEntity : Entity
{
    protected readonly ApplicationDbContext db;

    public IQueryable<TEntity> GetAll()
    {
        return db.Set<TEntity>().Where(e => !e.IsDeleted)
            .InterceptWith(new InjectConditionVisitor<Entity>(entity => !entity.IsDeleted));
    }

    public IQueryable<TEntity> GetAll(Expression<Func<TEntity, bool>> predicate)
    {
        return GetAll().Where(predicate);
    }

    public IQueryable<TEntity> GetAllWithDeleted()
    {
        return db.Set<TEntity>();
    }

    ...
}
Run Code Online (Sandbox Code Playgroud)

InterceptWith 函数来自此项目:https://github.com/davidfowl/QueryInterceptorhttps://github.com/StefH/QueryInterceptor(与异步实现相同)

an 的用法IStore<Project>如下:

var project …
Run Code Online (Sandbox Code Playgroud)

.net c# linq expression-trees entity-framework-6

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

使用 ramda.js 路径改变对象

我有一个结构,像这样

   [{
      title: "Section 1",
      items: [{
          title: 'Dashboard',
          icon: 'tachometer-alt',
          route: '/dashboard',
          opened: false
        },
        {
          title: 'Appointments',
          icon: 'calendar-alt',
          route: '/appointments',
          opened: true
        },
        {
          title: 'Orders',
          icon: 'box',
          route: '/orders',
          opened: false,
          children: [{
            title: 'Orders submenu 1',
            route: '/orders/sub1',
            opened: false,
            children: [{
              title: 'Orders submenu 1 subsubmenu 1',
              route: '/orders/sub1/sub1sub1'
            }]
          }]
        }
      ]
    }]
Run Code Online (Sandbox Code Playgroud)

这些基本上是带有菜单项的部分,每个菜单项都可以包含子菜单,子菜单有子子菜单等。

我有一个切换函数,它正在获取一个属性数组。我想否定这个数组“标记”的变量,所以当我得到一个[0, 'items', 2, 'children', 0, 'opened']数组时,预期的行为是“订单子菜单 1”的“打开”属性设置为“真”。

属性索引器数组也是可变的,所以如果需要,我可以稍微调整一下。

使用 Ramda,我可以轻松获取当前值,R.path([0, 'items', 1, 'opened'], menu)但如何将其设置为“true”?

jsfiddle …

javascript ramda.js

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