我有一个名为 Subscriptions 的表。我想将该表中的任何 LINQ 选择重定向到 Moles lambda,以便从该表中只返回 3 行——基本上我想绕过对数据库的调用。到目前为止,我的代码如下所示:
// lazy loader is here to handle successive calls to the
// same table (otherwise there's an error)
// CM is a namespace alias
Table<CM.Subscriptions> subsTable = null;
MTheDataContext.AllInstances.SubscriptionsGet = (c) =>
{
if (subsTable == null)
{
subsTable = c.GetTable<CM.Subscriptions>();
subsTable.Attach(new CM.Subscriptions() { SubID = 1,
StatusCode = 1, CustomerID = custID1 });
subsTable.Attach(new CM.Subscriptions() { SubID = 2,
StatusCode = 1, CustomerID = custID2 });
subsTable.Attach(new CM.Subscriptions() { SubID = 3,
StatusCode = 4, CustomerID = custID3 });
// c.Refresh(RefreshMode.KeepCurrentValues, t);
}
return subsTable;
};
不幸的是,它不起作用。我在数据库的 Subscriptions 表中有大约 1000 行。当我运行一些包含此重定向的测试代码时,我从数据库中获取了 1000 行,而不是重定向方法中的 3 行。显然我错过了一些东西。每当从订阅中选择任何测试代码时,我该怎么做才能只返回这 3 行?我对 3 个不同的表进行了 3 次调用,它们都需要选择数据库中没有的数据才能使该测试正常工作。
from sub in dc.Subscriptions ...
澄清:当我做一个选择时,对重定向方法的调用确实发生了。但返回的行不是重定向中的行。