【问题标题】:Get a row from A Table By Key in Entity Framework在实体框架中按键从表中获取一行
【发布时间】:2015-01-03 18:27:00
【问题描述】:

我有 2 个这样定义的表:

一号:

public class InputEmail
{
    [Key]
    public string EmailAddress { get; set; }

    public string Hostname { get; set; }

    public string Password { get; set; }

    public int PortNo { get; set; }

    public virtual OutputEmail OutputEmails { get; set; }
}

2号:

public class OutputEmail
{
    [Key]
    public string EmailAddress { get; set; } 
}

在我的程序中,我有一个 Combobox,我在其中加载来自 InputEmail 的电子邮件,目标是根据用户从 Combobox 中选择的电子邮件,在我的表格中以电子邮件为键的整行中显示一个消息框。

我正在考虑使用 .Find thingy,但我似乎无法弄清楚如何让它发挥作用。如果有人可以将我链接到 this 之类的页面或我可以阅读此内容的页面,我将不胜感激。

【问题讨论】:

  • 你试过 context.InputEmail.FirstOrDefault(x=>x.EmailAddress ==val)?

标签: c# winforms entity-framework .net-4.5


【解决方案1】:

我是这样使用 Find 功能的:

 string combo = comboBox1.SelectedValue.ToString();
 var rand = ctx.InputEmails.Find(combo);

Console.WriteLine(rand.EmailAddress);

它返回了我正在寻找的特定项目。

【讨论】:

    猜你喜欢
    • 2013-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    相关资源
    最近更新 更多