locked
c# entity framework database.sqlquery RRS feed

  • Question

  • I'm using Entity Framework. I have a query which joins 4 tables. Do I have a chance to use this query directly? As following:

    var komut = db.Database.SqlQuery<Bom>("SELECT ATANAN_PERSONEL as 
        ATANAN,PERSONELIND,GSM_NO as GSM1,GSM_NO_2 AS 
        GSM2,YETKILI,ARIZA,FIRMA,SUBE,convert(nvarchar,OLUSTURMA_TARIH,120) AS 
        OLUSTURMA_TARIHI,MUHATTAP,ACILIYET,arızalar.DURUM,arızalar.Id as 
        Id,iskabul.ISKABUL_DURUMU,arızalar.FIRMAIND,arızalar.RANDEVU_TARIH+' 
        '+ISNULL(RANDEVU_SAATI,'') AS RandevuTarihi FROM TBL_ARIZALAR AS arızalar LEFT 
        JOIN TBL_SUBELER AS sube ON arızalar.SUBEIND = sube.Id LEFT JOIN TBL_CARI AS 
        cari ON cari.Id = sube.CARIIND LEFT JOIN TBL_ISKABUL as iskabul ON 
        arızalar.Id=iskabul.ARIZAIND where  arızalar.EMANET='FALSE' and 
        arızalar.BEKLEMEDE='TRUE'  and SERVIS IS NULL and GUNLUK IS NULL and TEKLIF IS 
        NULL order by Id asc");
                         gridControl1.DataSource = komut.ToList();

    However, this returns grid view, with correct number of rows, without cell values

    What is wrong with my query?


    • Moved by CoolDadTx Thursday, June 21, 2018 1:52 PM EF related
    Thursday, June 21, 2018 5:44 AM

All replies

  • EF issues can be addressed at the EF forum.

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetentityframework

    Thursday, June 21, 2018 7:11 AM
  • If you're using EF then why would you be building the query manually? Just use EF for this.

    I suspect your query is probably correct. Unless your Bom type is a string then EF would convert the results of the query into a Bom. Take a look in the debugger at the values in komut and see if they are correct.

    My guess is that your binding in the UI is wrong.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, June 21, 2018 1:51 PM
  • Hi Anıldmrtas,

    What kind of project type you are using, Winforms, asp.net or others? Do you execute the SQL statement in your database, does it return the correct result?  Could you please share a simple sample which could reproduce the issue, such as a simple complete sample with related database, you could share it via OneDrive. it will be beneficial to resolve the issue.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 22, 2018 1:01 AM