We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Binding to EF joined tables

Hi there,

I'm playing arround with the sfdatagrid.
I want to have a twoway binding.
If I'm Setting ItemsSource like below:

 var newProjects = (from g in KSDB.tblGesehen
                              join p in KSDB.Projekte
                              on g.ProjektID equals p.ID
                              where g.Gesehen == false
                              select new
            dgNewProjects.ItemsSource = newProjects;

The grid Shows data as expected.
If I make chances in a cell all the expected Events were fired but the value of the current cell or row is Always inital loaded value, so I can't save back the updated value.
 Another concern is, I've got a boolean value that's visualized as Checkbox. When changing the Checkbox valuie by clicking it, the only Event that Comes up is CurrentCellValueChanged. I expexted to also the Events for RowValidated and RowValidating would fire.

Thanks in advance


4 Replies

TI Timo December 28, 2019 12:21 AM UTC

Finally got it.
Just made a view class:

 class NewProjects
/*        public tblGesehen gesehen { get; set; }
        public Projekte Projekte { get; set; }
        public Mitarbeiter Mitarbeiter { get; set; }
        public Standort Auftraggeber { get; set; }
        public Standort Endkunde { get; set; }
        public Kunde KundeEndkunde { get; set; }
        public Kunde KundeAuftraggeber { get; set; }*/
        public int gesehenID { get; set; }
        public int gesehenMitarbeiterID { get; set; }
        public bool gesehenGesehen { get; set; }
        public int gesehenProjektID { get; set; }
        public string Auftragsnummer { get; set; }
        public string Operation { get; set; }
        //public int MitarbeiterID { get; set; }
        public string MitarbeiterName { get; set; }
        public string Auftragsakte { get; set; }
        public string ProjektInfo { get; set; }
        public string Endkunde { get; set; }
        public string Auftraggeber { get; set; }
    class vmgetNewProjects
        private List<NewProjects> _np;
        public List<NewProjects> lNewProjects
            get { return _np; }
            set { _np = value; }
        public vmgetNewProjects()
            using (KSDBEntities KSDB = new KSDBEntities())
                lNewProjects = (from tgelesen in KSDB.tblGesehen
                                join tProjekte in KSDB.Projekte on tgelesen.ProjektID equals tProjekte.ID
                                join tStandortAuftraggeber in KSDB.Standort on tProjekte.Auftraggeber equals tStandortAuftraggeber.ID
                                join tKundeAuftaggeber in KSDB.Kunde on tStandortAuftraggeber.KundeID equals tKundeAuftaggeber.ID
                                join tStandortEndkunde in KSDB.Standort on tProjekte.Endkunde equals tStandortEndkunde.ID
                                join tKundeEndkunde in KSDB.Kunde on tStandortEndkunde.KundeID equals tKundeEndkunde.ID
                                join tMitarbeiter in KSDB.Mitarbeiter on tgelesen.MitarbeiterID equals tMitarbeiter.ID
                                where tgelesen.Gesehen == false
                                select new NewProjects
                                    gesehenGesehen = tgelesen.Gesehen,
                                    gesehenID = tgelesen.ID,
                                    gesehenMitarbeiterID = tgelesen.MitarbeiterID,
                                    gesehenProjektID = tgelesen.ProjektID,
                                    Auftragsnummer = tProjekte.Auftragsnummer,
                                    Operation = tProjekte.Operation,
                                    //MitarbeiterID = tgelesen.MitarbeiterID,
                                    Auftragsakte = tProjekte.Auftragsakte,
                                    ProjektInfo = tProjekte.ProjektInfo,
                                    MitarbeiterName = tMitarbeiter.Vornamen + " " + tMitarbeiter.Nachname,
                                    Auftraggeber = tKundeAuftaggeber.Name + " " + tStandortAuftraggeber.Ort,
                                    Endkunde = tKundeEndkunde.Name + " " + tStandortEndkunde.Ort
                                    /*Projekte = tProjekte,
                                    Mitarbeiter = tMitarbeiter,
                                    Endkunde = tStandortEndkunde,
                                    Auftraggeber = tStandortAuftraggeber,
                                    KundeEndkunde = tKundeEndkunde,
                                    KundeAuftraggeber = tKundeAuftaggeber*/

So I was able to set DataContext to NewProjects and ItemsSource to lNewProjects.
Don't know if that's the expected way, but works.

But the Checkbox still doesn't raise the RowValidated.


SS Susmitha Sundar Syncfusion Team December 30, 2019 01:29 PM UTC

Hi Timo, 
Thank you for using Syncfusion controls. 
Query 1: I was able to set DataContext to NewProjects and ItemsSource to lNewProjects. 
Don't know if that's the expected way, but works. 
   You need to set the DataContext and then set the ItemsSource for SfDataGrid. This is the correct way to binding the data to SfDataGrid. Please refer the more details about databinding from below UG documentation, 
Query 2: the Checkbox still doesn't raise the RowValidated. 
   In default, validations events not raised for GridCheckBoxColumn. But you can achieve this by marking current row validated flag as false using ValidationHelper.SetCurrentRowValidated method in CurrentCellValueChanged event. Please refer the below kb link for sample and code snippet, 
Please let us know if you need further assistance on this. 
Susmitha S 

TI Timo December 31, 2019 02:01 AM UTC

Hi Susmitha,
this means my approach for first Query was right?

For second query your answer worked like a Charme.

Thank you very much!


FP Farjana Parveen Ayubb Syncfusion Team December 31, 2019 06:15 AM UTC

Hi Timo, 
Thank you for your update. 
Yes, your approach for first query is right. We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
Farjana Parveen A 

Live Chat Icon For mobile
Up arrow icon