1
A
回答
3
定义您的数据上下文类的功能如下:
[TableFunction(Name="GetParentByID")]
public Table<Parent> GetParentByID(int? id)
{
return GetTable<Parent>(this, (MethodInfo)MethodBase.GetCurrentMethod(), id);
}
用法:
[Test]
public void Func2()
{
using (var db = new TestDbManager())
{
var q =
from c in db.Child
from p in db.GetParentByID(2)
select p;
q.ToList();
}
}
SQL:
SELECT
[t2].[ParentID],
[t2].[Value1]
FROM
[Child] [t1], [GetParentByID](2) [t2]
你也可以把它定义数据之外上下文:
public class Functions
{
private readonly IDataContext _ctx;
public Functions(IDataContext ctx)
{
_ctx = ctx;
}
[TableFunction]
public Table<Parent> GetParentByID(int? id)
{
return _ctx.GetTable<Parent>(this, (MethodInfo)(MethodBase.GetCurrentMethod()), id);
}
[TableExpression("{0} {1} WITH (TABLOCK)")]
public Table<T> WithTabLock<T>()
where T : class
{
return _ctx.GetTable<T>(this, ((MethodInfo)(MethodBase.GetCurrentMethod())).MakeGenericMethod(typeof(T)));
}
}
[Test]
public void Func1()
{
using (var db = new TestDbManager())
{
var q =
from p in new Functions(db).GetParentByID(1)
select p;
q.ToList();
}
}
[Test]
public void WithTabLock()
{
using (var db = new TestDbManager())
{
var q =
from p in new Functions(db).WithTabLock<Parent>()
select p;
q.ToList();
}
}
SQL:
SELECT
[p].[ParentID],
[p].[Value1]
FROM
[GetParentByID](1) [p]
SELECT
[p].[ParentID],
[p].[Value1]
FROM
[Parent] [p] WITH (TABLOCK)
相关问题
- 1. bltoolkit插入数据到表
- 2. 使用BLToolkit和Linq的标量函数
- 3. BlToolkit中存在
- 4. DataAccessor中的BLToolkit输出参数
- 5. 在BLToolkit
- 6. 与BLToolkit
- 7. BLToolkit + T4代+ MySQL数据库
- 8. BLToolkit对象作为参数
- 9. BLToolkit协会的LINQ
- 10. 表值函数
- 11. 表值函数
- 12. 表值函数
- 13. BLToolKit:当执行
- 14. BLtoolkit协会
- 15. BLToolKit:如何插入对象列表?
- 16. Oracle表值函数
- 17. SQL表值函数
- 18. SQL Server中的表值函数;函数中的表是暂时的?
- 19. BLToolkit Oracle SP支持
- 20. BLToolkit MapValue未映射
- 21. 如何通过BlToolkit
- 22. 表变量在表中值函数
- 23. NHibernate的 - 表值函数
- 24. 带cte的表值函数
- 25. SELECT语句中的SQL表值函数
- 26. EF 5中的表值函数?
- 27. 实体框架中的值表函数?
- 28. Haskell中匿名函数的真值表
- 29. BLToolKit生成错误的SQL
- 30. 使用MySQL连接的BLToolkit