下面是简单的 SQL 查询
select RelationshipID from Relationships r
where
r.RequestReceiverID = 3 and
r.RequestSenderID = (select MemberID from Members m
where m.Name = 'Cipla')
上面的查询工作正常,给了我预期的结果。
我目前正在尝试学习 LINQ
因此,我尝试将上述 SQL 查询转换为 LINQ
这是我的尝试
var relation =
(from relationship in db.RelationShips
where relationship.RequestReceiverID == LoggedInUserID &&
relationship.RequestSenderID ==
(from m in db.Members
where m.Name == SelectedUserName
select m.MemberID).FirstOrDefault()
select relationship).FirstOrDefault();
但是在执行上述查询时,出现以下错误
Invalid column name 'Member_MemberID'.
Invalid column name 'Member_MemberID1'.
编辑
接下来我正在尝试更新数据库中的数据
relation.StatusID = (from p in db.StatusMasters
where p.Status == Status
select p.StatusID).FirstOrDefault();
db.SaveChanges();
根据 AgentFire 的要求进行了编辑
//Members.cs
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace Munim_File_Sharing.Models
{
public class Member
{
[Key]
public int MemberID { get; set; }
public string Name { get; set; }
public string Password { get; set; }
public string MobileNo { get; set; }
public string FileName { get; set; }
public DateTime MemberSince { get; set; }
public int MemberTypeID { get; set; }
public List<Payment> Payments { get; set; }
public List<Relationship> RelationshipSender { get; set; }
public List<Relationship> RelationshipReceiver { get; set; }
}
}