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

C# 检索结果集并将其缓存到我的应用程序中,c#,entity-framework,fingerprint,digital-persona-sdk,C#,Entity Framework,Fingerprint,Digital Persona Sdk,我在一个表中有一个byte[]列,其中存储了指纹数据。我希望只查询一次表中的行,并将记录集存储在变量中或代码中的某个位置,这样就不必每次都查询数据库。查询将返回数千行 这将为我获取所有记录: var table = (from a in context.tblFingerprints select new {a} ).ToList(); 我尝试在AppData类中声明一个变量:public List TableData 然后尝试将变量

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

这将为我获取所有记录:

var table = (from a in context.tblFingerprints
                              select new {a} ).ToList();
我尝试在AppData类中声明一个变量:
public List TableData
然后尝试将变量“table”值存储到它

Data.TableData = table;
错误仍然存在:

无法将类型
'System.Collections.Generic.List'
隐式转换为
'System.Collections.Generic.List'

以下是我希望查询结果返回的行以匹配指纹的方式:

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)
        {...}
    }
}

有什么想法吗?

您正在使用
选择新{a}
将这些作为新对象返回。如果
context.tblFingerprints
属于
TableData
类型,则只需
选择一个

var table = (from a in context.tblFingerprints
                          select a).ToList();
  • 您不需要
    selectnew{a}
    (这是在创建一个新的匿名类型,整个记录只有一个成员,这很愚蠢。
    • 您也不需要任何Linq表达式,只需直接在
      DbSet
      上使用
      ToList()
  • 将结果存储在静态变量中
分类
{
私有静态列表\u指纹;
公营部门
{
DbContext上下文=。。。
如果(_指纹为空)
{
_指纹=context.tblFingerprints.ToList();
}
//用“你的指纹”做东西`
}
}
删除“new{a}”并替换为“a”,告诉ToList这是一个对象列表

var table = (from a in context.tblFingerprints
             select a).ToList<object>();
var table=(来自context.tblFingerprints中的
选择一个.ToList();

上下文的数据类型是什么。tblFingerprints
?数据库设计用于查询,是否遇到性能问题?@MichaelRandall嗯,随着我的数据库的增长,检索和比较一个指纹与数千条记录需要更多的时间。
var table = (from a in context.tblFingerprints
             select a).ToList<object>();