1.在联结多表的查询场景中,究竟是使用类似于左联结的from x in table……这种表达式语法好还是使用扩展方法GroupJoin比较好?听别人说使用GroupJoin()扩展方法会生成冗余的sql脚本,如果不喜欢from x in table这种写法,是否有办法可以对GroupJoin()扩展方法进行优化?
2.不使用多表联结查询。而是使用子查询,就像下面代码所示那样,是否会影响性能?或者产生冗余的sql脚本?
var query = db.T_JZX_MONEYSET.Where( e => e.I_ID_CUSTOMER == dec_customerId && e.I_BSTYPE == -1 ).Select( e => new GRID_BILLMONEY
{
ID = -10000,
I_ID_INOUT = e.I_ID_INOUT,
NVC_NAME_INOUT = db.T_BASE_INOUTTYPE.Where( inout => inout.ID == e.I_ID_INOUT ).Select( inout => inout.NVC_NAME ).Min( ),
I_ID_CUSTOMER = e.I_ID_CUSTOMER,
I_ID_INOUTTYPE = e.I_TYPE,
NVC_NAME_CUSTOMER =
e.I_TYPE == 1 ?
db.T_KH_CUSTOM.Where( customer => customer.ID == e.I_ID_CUSTOMER ).Select( customer => customer.NVC_NAME ).FirstOrDefault( )
:
db.T_KH_SUPPLY.Where( supply => supply.ID == e.I_ID_CUSTOMER ).Select( customer => customer.NVC_NAME ).FirstOrDefault( ),
I_ID_MONEY = rmb,
NVC_NAME_MONEY = "人民币",
I_ID_TAX = 0,
NVC_NAME_TAX = "",
N_RATE = 1.00m,
N_MONEY = e.N_MONEY,
N_TAXRATE = 0,
N_SHMONEY = 0,
DT_DATE = e.DT_WRITE,
I_BL = 0,
I_STATE = e.I_STATE,
NVC_REMARK = e.NVC_REMARK
} );