检索结果集并将其缓存到我的应用程序中

问题描述 投票:0回答:3

我在存储指纹数据的表中有一个byte[]列。我希望只查询一次表中的行,并将记录集存储在变量中或代码中的某个位置,这样就不必每次都查询数据库。该查询将返回数千行。

这将为我获取所有记录:

var table = (from a in context.tblFingerprints
                              select new {a} ).ToList();

我尝试在AppData类中声明一个变量:public List<object> TableData;然后尝试将变量“表”值存储到其中。

Data.TableData = table;

错误仍然存​​在:

无法将类型'System.Collections.Generic.List<<anonymous type: FingerprintTEST.tblFingerprint a>>'隐式转换为'System.Collections.Generic.List<object>'

这是我希望查询从结果返回的行以匹配指纹的方法:

foreach (var row in Data.TableData)
{
    Template tem = new Template();
    tem.DeSerialize(row.a.fingerTemplate);

    if (tem != null)
    {
        // Compare feature set with particular template.
        Verificator.Verify(features, tem, ref res);

        if (res.Verified)
        {...}
    }
}

请问有什么想法吗?

c# entity-framework fingerprint digital-persona-sdk
3个回答
0
投票

您将使用select new {a}将它们作为新对象返回。如果context.tblFingerprints的类型为TableData,则只需要select a


0
投票
  • 您不需要select new { a }(这是创建一个新的匿名类型,对于整个记录只有一个成员,这很愚蠢。
    • 您也根本不需要任何Linq表达式,只需直接在ToList()上使用DbSet

0
投票

删除“新{a}”并仅替换为“ a”,并告诉ToList它是对象列表。

© www.soinside.com 2019 - 2024. All rights reserved.