Entity Framework 4: Selecting Single Record

后端 未结 3 2033
孤城傲影
孤城傲影 2020-12-06 00:10

I\'m currently planning on switching my \"manual query-writing\" code to a nice SQL framework, so I can leave the queries or sql things to the framework, instead of writing

相关标签:
3条回答
  • 2020-12-06 00:59

    You can use Single or First methods.

    The difference between those methods is that Single expects a single row and throws an exception if it doesn't have a single row.

    The usage is the same for both of them

    0 讨论(0)
  • 2020-12-06 01:01

    (Based on VS 2015) If you create an .edmx (Add --> ADO.NET Entity Data Model).

    Go through the steps to created the ".edmx" and use the following to run the stored procedure. emailAddress is the parameter you are passing to the stored procedure g_getLoginStatus. This will pull the first row into LoginStatus and status is a column in the database:

    bool verasity = false;
    DBNameEntities db = new DBNameEntities();   // Use name of your DBEntities
    
    var LoginStatus = db.g_getLoginStatus(emailAddress).FirstOrDefault();
    
    if ((LoginStatus != null) && (LoginStatus.status  == 1))
    {
          verasity = true;
    }
    
    0 讨论(0)
  • 2020-12-06 01:05
    var address = Context.Addresses.First(a => a.Id == addressId);
    
    0 讨论(0)
提交回复
热议问题