Linq 链接MapHierarchy()以首先在EF代码中添加更多案例
我希望这会有一个疯狂的linq答案,感觉应该有 当前代码:Linq 链接MapHierarchy()以首先在EF代码中添加更多案例,linq,entity-framework,code-first,Linq,Entity Framework,Code First,我希望这会有一个疯狂的linq答案,感觉应该有 当前代码: MapHierarchy().Case<Folder>(f => new { FolderId = f.Id, f.Name, Type = 1 }) .Case<RootFolder>(f =>
MapHierarchy().Case<Folder>(f => new { FolderId = f.Id,
f.Name,
Type = 1 })
.Case<RootFolder>(f => new { f.RootName,
Type = 2 })
.ToTable("Folder");
MapHierarchy().Case(f=>new{FolderId=f.Id,
f、 名字,
类型=1})
.Case(f=>new{f.RootName,
类型=2})
.ToTable(“文件夹”);
另一种方法:
void AddAnotherFolder(something)
{
something.Case<RootFolder>(f => new { f.RootName, Type = 2 })
}
void AddAnotherFolder(某物)
{
Case(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");
MapHierarchy().Case(f=>new{FolderId=f.Id,
f、 名字,
类型=1})
.Case(f=>new{f.RootName,
类型=2})
.AddAnotherFolder(此)
.ToTable(“文件夹”);
这感觉像一个linq问题,如果它可以查看
案例的方法签名,那将非常酷。您应该能够在静态类中为特定类型创建一个类似的扩展方法,其中包含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 });
}
}
公共静态类ExtensionClass
{
公共静态HierarchyEntityMap AddAnotherFolder(此HierarchyEntityMapGenerator源),其中tenty:RootFolder
{
返回source.Case(f=>new{f.RootName,Type=2});
}
}
要调用它,只需执行.AddAnotherFolder()
,而不使用(this)
[未测试,但会是这样]查看案例的方法签名。您应该能够在静态类中为特定类型创建一个类似的扩展方法,其中包含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 });
}
}
公共静态类ExtensionClass
{
公共静态HierarchyEntityMap AddAnotherFolder(此HierarchyEntityMapGenerator源),其中tenty:RootFolder
{
返回source.Case(f=>new{f.RootName,Type=2});
}
}
要调用它,只需执行.AddAnotherFolder()
,而不使用(this)
[未经测试,但会是这样]