[英]Get a row from A Table By Key in Entity Framework
I have 2 tables defined like this: 我有2个这样定义的表:
Number 1: 1号:
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; }
}
Number 2: 2号:
public class OutputEmail
{
[Key]
public string EmailAddress { get; set; }
}
In my program I have a Combobox in which I load the emails from InputEmail and the goal is that depending on what email the user selects from the Combobox the entire row in my table for which the email is the key to be shown in a messagebox. 在我的程序中,我有一个组合框,可以在其中加载来自InputEmail的电子邮件,其目标是根据用户从组合框中选择的电子邮件,在我的表中整行(该电子邮件是要在消息框中显示的键)。
I was thinking of using the .Find thingy but I can't seem to figure out how to make it work. 我当时在考虑使用.Find东西,但似乎无法弄清楚该如何工作。 If someone can link me to a page like this or to a page where I can read up on this I would gladly appreciate it.
如果有人可以链接我像一个页面这样或一个网页,我可以阅读了关于这一点,我会很乐意欣赏它。
I used the Find function like this : 我这样使用Find函数:
string combo = comboBox1.SelectedValue.ToString();
var rand = ctx.InputEmails.Find(combo);
Console.WriteLine(rand.EmailAddress);
And it returned the specific items which I was looking for. 它返回了我正在寻找的特定物品。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.