1

这是我的 LINQ 查询,请帮助我将此 LINQ 查询更改为使用 Lambda 表达式进行查询:

var query = from d in db.customers
            from s in db.tbl_states
            where d.cust_state == s.state_id
            select new
            {
                d.cust_name,
                s.state_name
            };
4

3 回答 3

2

尝试这个:

var query =
    db.customers.Join (         
        db.tbl_states,        
        d => d.cust_state,       
        s => s.state_id,   
        (d, s) => new { d.cust_name, s.state_name }
    );
于 2013-01-20T00:48:01.513 回答
2

这应该这样做:

var query = db.customers.Join(db.tbl_states, d => d.cust_state, s => s.state_id, (d, s) => new { d.cust_name, s.state_name });
于 2013-01-20T00:48:14.360 回答
2

我想你linq的应该是这样的

var query = from d in db.customers
            join s in db.tbl_states on d.cust_state equals s.state_id
            select new
            {
                d.cust_name,
                s.state_name
            };

为了Lambda

var list = db.customers                     
.Join(db.tbl_states, 
      s => s.tbl_states, 
      d => d.state_id, 
      (s, d) => new                                                                                         
                 {
                     d.cust_name,
                     s.state_name
                 });
于 2013-01-20T00:55:36.123 回答