嗨,我对 akka.net 很陌生!所以对任何奇怪的问题表示歉意:-)
我正在研究访问数据库的演员。一个是阅读,一个是写作。两者都由路由器根据工作负载根据需要创建它们。
为了避免为数据库中的每种类型创建,我想将泛型与表达式结合使用。消息大致如下:
public class Msg<T>
{
public Expression<Func<IEnumerable<T>, T, IEnumerable<T>>> Expr { get; }
public MsgExprObjBool (Expression<Func<IEnumerable<T>, T, IEnumerable<T>>> expr)
{
Expr = expr;
}
}
在演员中,我想使用定义的表达式并根据请求检索实体以进行进一步处理或至少将它们发回 - 如下所示:
public class MyActor : ReceiveActor
{
public MyActor ()
{
Receive<MsgExprBool<Foo>> (s => Console.WriteLine ($"Result<Material> == {s.Expr.Compile () (_foos)}"));
Receive<MsgExprBool<Boo>> (s => Console.WriteLine ($"Result<Boo> == {s.Expr.Compile () (_boos)}"));
Receive<MsgExprObjBool<Qoo>> (s =>
{
foreach (var r in s.Expr.Compile () (_Qoos, qoo))
Console.WriteLine ($"Result<Qoo> == {q.Id}, {q.Name}");
});
}
}
我现在的问题是,有没有人使用这种方法来访问数据库,如果是,有什么经验?
REM:由于参与者系统不与任何外部请求者进行通信,所有请求者都共享一组公共对象定义 - 就像数据库对象一样。