1

我希望对此会有一个疯狂的 linq 答案,感觉应该有

当前代码:

MapHierarchy().Case<Folder>(f => new { FolderId = f.Id, 
                                        f.Name,
                                        Type = 1 })
                      .Case<RootFolder>(f => new { f.RootName,
                                                    Type = 2 })
                      .ToTable("Folder");

另一种方法:

void AddAnotherFolder(something)
{
   something.Case<RootFolder>(f => new { f.RootName, Type = 2 })
}

我想做的就是将该方法传递给 MapHierarchy 字符串——这可能吗?

就像是...

MapHierarchy().Case<Folder>(f => new { FolderId = f.Id, 
                                        f.Name,
                                        Type = 1 })
                      .Case<RootFolder>(f => new { f.RootName,
                                                    Type = 2 })
                      .AddAnotherFolder(this)
                      .ToTable("Folder");

感觉就像一个linq问题,如果可以的话会很酷

4

1 回答 1

1

查看Case<T>. 您应该能够在带有特定类型的 where 子句的静态类中创建类似的扩展方法。它可能看起来像这样:

public static class ExtensionClass
{
    public static HierarchyEntityMap<TEntity> AddAnotherFolder<TEntity>(this HierarchyEntityMapGenerator<TEntity> source) where TEntity:RootFolder
    {
       return source.Case<TEntity>(f => new { f.RootName, Type = 2 });
    }
}

并且要调用它,您只需.AddAnotherFolder()不使用(this)即可。

[未测试,但会是这样的]

于 2010-10-18T20:11:35.273 回答