如何将返回的强类型对象值分配给Label文本?

时间:2012-09-28 21:15:42

标签: c# entity-framework

我有一个存储过程,我在其实体框架模型中作为函数导入。我想将存储过程的一个值分配给我的label.text,但它不会出现在intellisense中。我一定做错了什么。有人可以帮忙吗?

    private void GetBackgroundData()
    {
        List<GetBackground_Result> results = context.GetBackground().ToList();
        lblFullName.Text = results.FullName  // FullName doesn't appear in my intellisense
    }

1 个答案:

答案 0 :(得分:1)

results是一个列表,而不是GetBackground_Result的单个实例。您需要从集合中获取单个元素来设置文本:

// if there could be multiple elements in the list
lblFullName.Text = results.First().FullName;

// or, if there should only be one element in the list
lblFullName.Text = results.Single().FullName;