EntityFrameWork+Oracle表/視圖 未定義主鍵,並且無法推斷有效主鍵

來源:互聯網
上載者:User
create or replace view mcerp_v_waitstockin asselect nvl(flngsaleorderid,1) flngsaleorderid,fchrsaleorderno,fdtmdate,flngaudit,flngcustomerid, fchrcustomername, fchrphone,flngpositionid, fchrpositioncode,fchrpositionname, fchrpositionfullname,flngdepartmentid, fchrdepartmentfullname,flngemployeeid,fchremployeecode, fchremployeename,flotquantity,fchrnote,flngreceipttypeid,fchrreceipttypefrom(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 fchrreceipttypefrom mcerp_purchaseorder mpinner  join department d on mp.flngdepartmentid = d.lngdepartmentidinner join employee e on mp.flngemployeeid = e.lngemployeeidinner join position p on mp.flngpositionid=p.lngpositionidleft join supplypreapp s on mp.flngsupplyid=s.lngsupplypreappidleft join customerex c on mp.flngsupplyid = c.lngcustomeridwhere  mp.flngaudit=1 and (mp.flngstock=0 or mp.flngstock=1)and mp.fbitclose=0union 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,單據類型strfrom mcerp_allocate ainner join position pp on pp.lngpositionid=a.flnginpositionidleft join employee e on e.lngemployeeid=a.flngemployeeidwhere a.flnginid<=0 and a.flngoutid>0union 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 fchrreceipttypefrom mcerp_otherinout ainner  join department d on a.flngdepartmentid = d.lngdepartmentidinner join position pp on pp.lngpositionid=a.flngpositionidleft join employee e on e.lngemployeeid=a.flngemployeeidleft join customerex c on a.flngcustomerid = c.lngcustomeridwhere 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語句。這樣就可以再程式中直接查詢調用這個視圖了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.