除了在asp.net MVC中使用实体freamwork的两个表之间

时间:2016-03-01 17:22:50

标签: asp.net-mvc except

我有三张桌子A,B,C;

//Table A
 public class Question
    {
        [Key]
        public int ID { get; set; }

        [Required]        
        public string Name { get; set; }

     }
//Table B
public class Answer
    {
        [Key]
        public int ID { get; set; }

        [Required]        
        public string Name { get; set; }

        [Required]        
        public int QusetionID { get; set; }

        [Required]        
        public int LocalID { get; set; }

     }

//Table C
public class Local
    {
        [Key]
        public int ID { get; set; }

        [Required]        
        public string Name { get; set; }

        [Required]        
        public int Localip { get; set; }
     }

什么是期望的查询本地未回答的问题 除了在两个矩阵中使用外,你如何使用? 使用Asp.net MVC中的实体框架 我想展示一些未回答的问题清单?

string ip = Request.UserHostAddress;
var answerip = db.Answer.Where(l => l.Local.Localip == ip );
var quslist = db.Qustions.Except(answerip);

1 个答案:

答案 0 :(得分:0)

List<int> tempIdList = answeripE.Select(q => q.ID).ToList();
var quslist = db.Qustion.Where(q => !tempIdList.Contains(q.ID));

感谢&#34; daryal&#34;的创建者 Get All Except from SQL database using Entity Framework