一个是EF内联多表查询,一个是EF中写SQL文。
public IList<MenuModel> GetAllMenu() { using (IMMEntities context = new IMMEntities()) { var menuList = from A in context.BASE_FUNCTION join B in context.BASE_MENU on A.FUNCTION_ID equals B.FUNCTION_ID select new MenuModel { Function = new FunctionModel() { FunctionId = A.FUNCTION_ID, FunctionName = A.FUNCTION_NAME }, MenuType = B.MENU_TYPE, PicName = B.PIC_NAME, MenuId = B.MENU_ID, MenuName = B.MENU_NAME, MenuStyleId = B.MENU_STYLEID, ParentId = B.PARENT_ID, Sort = B.SORT, Status = B.STATUS }; return menuList.ToList(); } }
EF多表查询。↑
public int insertBussiness(CasePublicModel businessModel) { using (IMMEntities context = new IMMEntities()) { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@TITLE",businessModel.Title), new SqlParameter("@CASE_TYPE_ID",businessModel.CaseTypeId), new SqlParameter("@DESCRIPTION",businessModel.Description), new SqlParameter("@PUBLISH_MEMBER_ID",businessModel.PublicMemberId), new SqlParameter("@AUTHOR_MEMBER_ID",businessModel.AuthorMemberId), new SqlParameter("@COIN",businessModel.Coin), new SqlParameter("@ANSWER_DESCRIPTION",businessModel.AnswerDescription), new SqlParameter("@STATUS",businessModel.Status), new SqlParameter("@PUBLISH_DT",businessModel.PublishDT), new SqlParameter("@ANONYMOUS",businessModel.Anonymous), new SqlParameter("@IMAGES_URI",businessModel.ImagesURI), new SqlParameter("@CHANGE_DT",businessModel.ChangeDT) }; context.Database.ExecuteSqlCommand(SQL_INSERT_BUSINESS_CASE, parameters); return context.SaveChanges(); } }
用context.Database.ExecuteSqlCommand(SQL文,参数数组)。↑