EntityFrameWork+Oracle表/视图 未定义主键,并且无法推断有效的主键
create or replace view mcerp_v_waitstockin as select nvl(flngsaleorderid,1) flngsaleorderid,fchrsaleorderno,fdtmdate,flngaudit, flngcustomerid, fchrcustomername, fchrphone, flngpositionid, fchrpositioncode,fchrpositionname, fchrpositionfullname, flngdepartmentid, fchrdepartmentfullname, flngemployeeid,fchremployeecode, fchremployeename, flotquantity,fchrnote,flngreceipttypeid,fchrreceipttype from ( select mp.flngpurchaseorderid flngsaleorderid,mp.fchrpurchaseorderno fchrsaleorderno,mp.fdtmdate,mp.flngaudit,-----待入库数据 mp.flngsupplyid flngcustomerid, c.strcustomername fchrcustomername,mp.fchrphone, mp.flngpositionid,p.strpositioncode fchrpositioncode, p.strpositionname fchrpositionname,p.strfullname fchrpositionfullname, mp.flngdepartmentid, d.strfullname fchrdepartmentfullname, mp.flngemployeeid, e.stremployeecode fchremployeecode, e.stremployeename fchremployeename, mp.flotquantity,mp.fchrnote,mp.flngreceipttypeid,case when flngreceipttypeid=1 then '采购入库' when flngreceipttypeid=2 then '采购退货' end fchrreceipttype from mcerp_purchaseorder mp inner join department d on mp.flngdepartmentid = d.lngdepartmentid inner join employee e on mp.flngemployeeid = e.lngemployeeid inner join position p on mp.flngpositionid=p.lngpositionid left join supplypreapp s on mp.flngsupplyid=s.lngsupplypreappid left join customerex c on mp.flngsupplyid = c.lngcustomerid where mp.flngaudit=1 and (mp.flngstock=0 or mp.flngstock=1)and mp.fbitclose=0 union all-------------调拨入库 select a.flngallocateid flngsaleorderid,a.fchrallocateno fchrsaleorderno,a.fdtmdate,a.flngaudit,----申请单ID,申请单号,单据日期,审核状态, 0 flngcustomerid, '' fchrcustomername,'' fchrphone,------客户id,客户名,客户电话 a.flnginpositionid flngpositionid,pp.strpositioncode fchrpositioncode,pp.strpositionname fchrpositionname,pp.strfullname fchrpositionfullname,----仓库 0 flngdepartmentid, '' fchrdepartmentfullname,-----部门 a.flngemployeeid,e.stremployeecode fchremployeecode,e.stremployeename fchremployeename,-----业务员 a.flotquantity,a.fchrnote,21 flngreceipttypeid,'调拨单' fchrreceipttype ----数量,备注,单据类型ID,单据类型str from mcerp_allocate a inner join position pp on pp.lngpositionid=a.flnginpositionid left join employee e on e.lngemployeeid=a.flngemployeeid where a.flnginid<=0 and a.flngoutid>0 union all------其他入库,其他入库退 select a.flngotherinoutid flngsaleorderid,a. fchrotherinoutno,a.fdtmdate,a.flngaudit, a.flngcustomerid, c.strcustomername fchrcustomername,c.strmovephone fchrphone, a.flngpositionid,pp.strpositioncode fchrpositioncode,pp.strpositionname fchrpositionname,pp.strfullname fchrpositionfullname, a.flngdepartmentid, d.strfullname fchrdepartmentfullname, a.flngemployeeid,e.stremployeecode fchremployeecode,e.stremployeename fchremployeename, a.flotquantity,a.fchrnote,flngreceipttypeid,case when flngreceipttypeid=31 then '其他入库申请' when flngreceipttypeid=32 then '其他入库退回' end fchrreceipttype from mcerp_otherinout a inner join department d on a.flngdepartmentid = d.lngdepartmentid inner join position pp on pp.lngpositionid=a.flngpositionid left join employee e on e.lngemployeeid=a.flngemployeeid left join customerex c on a.flngcustomerid = c.lngcustomerid where a.flngstock<>2 and a.flngauditid>0 and (a.flngreceipttypeid=31 or a.flngreceipttypeid=32)
以上为Oracle中的视图,添加几次该视图总是添加不进去
点完成后视图并没有添加进去
原因是视图sql中有 union all 关键字 EF无法推断出哪个是主键。
解决:
先将 union all下面的SQL删除掉,只留一个表的查询。然后更新视图。
更新视图后再在把union all加进SQL然后执行SQL语句。这样就可以再程序中直接查询调用这个视图了。