简体   繁体   English

在实体框架中通过键从表获取行

[英]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.

相关问题 使用隐藏的外键表和Linq向实体框架添加行 - Add row to Entity Framework with hidden foreign key table and Linq 使用实体框架将行插入到具有复合键的表中 - Using Entity Framework to insert row to a table that has a composite key C#实体框架,如何从通过Junction表创建的对象中获取主键 - C# Entity framework, how to get the primary key from an object created from a Junction table 如何从实体框架中的表中获取值? - How to get values from a table in entity framework? 如何使用 Entity Framework Core 从子表列表的每个订单中获取产品行? - How to get product row from each order of child table list using Entity Framework Core? 在实体框架中,如果存在行,则获取密钥/ ID,否则插入行并获取密钥 - In Entity Framework Get key/id if row exists else insert row and get the key 如何使用Entity Framework获取表中的最新行(考虑性能)? - How to get the latest row in a table using Entity Framework (considering performance)? 通过Entity Framework 6中另一个表中的外键获取记录 - Get records via foreign key in another table in Entity Framework 6 实体框架-更新表中的一行 - Entity Framework - Update a row in a table Entity Framework 6 中的单行表 - Single Row Table in Entity Framework 6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM