[EF]执行SQL语句

Sql Server
专注微软数据库技术:安全管理,存储过程,函数,游标,视图,T-SQL,算法等。
厦门德仔

//using System.Data.Entity.Infrastructure;

    using (var context = new KTStoreContext())
            {
                try
                {
                    String sql = "SELECT * FROM Product ";
                    DbSqlQuery<Product> query = context.Products.SqlQuery(sql);
                    List<Product> products = query.ToList();

                    foreach (Product product in products)
                    {
                        Console.WriteLine("{0}\t售价:{1}", product.Name, product.Price);
                    }
                    Console.WriteLine("\n商品项数:{0}", products.Count());
                }
                catch (Exception ex) {
                    Console.WriteLine("\n错误信息:{0}\n",ex.Message);
                    Console.WriteLine(ex.ToString());
                }
            }
            Console.ReadKey();
展开阅读全文

.net EF执行多表联查sql语句

11-17
select u.warningStatus,u.unitCode as unitCode,u.unitName as unitName,u.shortName as shortName,u.organizationCode as organizationCode,u.censusRegId as censusRegId,u.msgCenterCode as msgCenterCode, mes.msgCenterName as msgCenterName,u.regionCode as regionCode,r.regionName as regionName,u.unitTypeCode as unitTypeCode,d.DIC_TEXT as unitTypeName,u.economicTypeCode as economicTypeCode, ech.DIC_TEXT as economicTypeName,u.superviseLevelCode,s.DIC_TEXT as superviseLevelName,u.businessTypeCode as businessTypeCode,bus.DIC_TEXT as businessTypeName,u.unitTel as unitTel, u.unitAddress as unitAddress,u.unitEmail as unitEmail,u.unitFax as unitFax,u.postCode as postCode,u.establishedTime as establishedTime,u.connectTime as connectTime,u.onlineStatusCode as onlineStatusCode, f.DIC_TEXT as onlineStatusName,u.workForce as workForce,u.controlCenterNum as controlCenterNum,u.legalPersonCode as legalPersonCode,unit.unitManName as unitManName,u.responsibleManCode as responsibleManCode, unit1.unitManName as responsibleManName,u.fireManagerCode as fireManagerCode,unit2.unitManName as fireManagerName,u.fixedAssets as fixedAssets,u.floorSpace as floorSpace,u.buildingArea buildingArea, u.defendDepartmentTel as defendDepartmentTel,u.propertyMngCode as propertyMngCode,mng.enterpriseName as enterpriseName,u.detectUnitCode as detectUnitCode,detect.enterpriseName as detectName,u.operationUnitCode as operationUnitCode, u.operationUnitCode as operationUnitCode,operate.enterpriseName as operateName,u.maintainUnitCode as maintainUnitCode,maintain.enterpriseName maintainName,u.unitBrigadeCode as unitBrigadeCode,fireBrigade.fireBrigadeName as fireBrigadeName, u.longitude as longitude,u.latitude as latitude,u.isMonitor as isMonitor,u.isVideo as isVideo,u.grographyInfo as grographyInfo,u.otherInfo as otherInfo,u.superviseUserCode as superviseUserCode,usr.userName as userName,u.remark as remark, u.policeCode as policeCode,police.departmentName as policeName,u.brigadeCode as brigadeCode,brigade.departmentName as brigadeName,u.detachmentCode as detachmentCode,detachment.departmentName as detachmentName from b_unit u left join e_messageCenter mes on u.msgCenterCode=mes.msgCenterCode left join e_fireDepartment police on u.policeCode=police.departmentCode left join e_fireDepartment brigade on u.brigadeCode=brigade.departmentCode left join e_fireDepartment detachment on u.detachmentCode=detachment.departmentCode left join b_unitMan unit on u.legalPersonCode=unit.unitManCode left join b_unitMan unit1 on u.responsibleManCode=unit1.unitManCode left join b_unitMan unit2 on u.fireManagerCode=unit2.unitManCode left join e_propertyMng mng on u.propertyMngCode=mng.enterpriseCode left join e_detect detect on u.detectUnitCode=detect.enterpriseCode left join e_operate operate on u.operationUnitCode=operate.enterpriseCode left join e_maintain maintain on u.maintainUnitCode=maintain.enterpriseCode left join b_unitFireBrigade fireBrigade on u.unitBrigadeCode=fireBrigade.fireBrigadeCode left join b_sysUser usr on u.superviseUserCode=usr.userCode left join sys_dic bus on u.businessTypeCode=bus.DIC_CODE and bus.DIC_SORT='businessType' left join sys_dic ech on u.economicTypeCode=ech.DIC_CODE and ech.DIC_SORT='economicType' left join sys_dic d on u.unitTypeCode=d.DIC_CODE and d.DIC_SORT='unittype' left join sys_dic s on u.superviseLevelCode=s.DIC_CODE and s.DIC_SORT='UnitType' left join sys_dic f on u.onlineStatusCode=f.DIC_CODE and f.DIC_SORT='online' left join d_region r on u.regionCode=r.regionCode where u.unitCode='1305U00002' and u.contactDelete=1 这是一条sql 语句, 我返回的是多表的中的多列。并不是一张表的列,如何用ef 执行并得到返回的列 ![图片说明](https://img-ask.csdn.net/upload/201611/17/1479346658_968759.png)
©️2020 CSDN 皮肤主题: 鲸 设计师: meimeiellie 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值