0

Could someone please convert the below raw sql to linq ?

_sql= " SELECT tbl_book.*, tbl_time.tt_scope, tbl_time.tt_time "+
      " FROM tbl_time "+ 
      " LEFT OUTER JOIN tbl_book ON tbl_time.tt_time = tbl_book.book_time "+
      " AND (tbl_book.ppt_id=@ppt_id AND tbl_book.fct_id=@fct_id "+
      " AND tbl_book.book_date=@book_date)";
guisantogui
  • 4,017
  • 9
  • 49
  • 93
Taylern
  • 116
  • 1
  • 13

1 Answers1

0

if

var ppt_id_param = "@ppt_id";
var fct_id_param = "@fct_id";
var book_date_param = "@book_date";

be our params, and your context be this:

TestEntities DBContext = new TestEntities();

your linq query is like:

var query = (from time in tbl_time
             join book in tbl_book on time.tt_time equals book.book_time 
                 into joinedList
             from book in joinedList.DefaultIfEmpty()
             where book == null ? 
                 true :
                 (
                      book.ppt_id == ppt_id_param &&
                      book.fct_id == fct_id_param &&
                      book.book_date == book_date_param &&
                 )
             select new {

                 time.tt_scope,
                 time.tt_time
                 book
             })
             .ToList();
Amir Sherafatian
  • 2,083
  • 2
  • 20
  • 32