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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Binding to EF joined tables

Thread ID:

Created:

Updated:

Platform:

Replies:

150198 Dec 25,2019 05:54 PM UTC Dec 31,2019 06:15 AM UTC WPF 4
loading
Tags: SfDataGrid
Timo
Asked On December 25, 2019 05:54 PM UTC

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
                              {
                                  Gesehen=g.Gesehen,
                                  p.Auftragsnummer,
                                  p.Auftraggeber,
                                  p.Endkunde,
                                  p.Operation,
                                  g.MitarbeiterID,
                                  p.Auftragsakte,
                                  p.ProjektInfo
                              }).ToList();
          
              
               
            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

Timo


Timo
Replied On 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*/
                                }).ToList();
            }
        }
    }

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.

Timo

Susmitha Sundar [Syncfusion]
Replied On 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. 
 
Regards, 
Susmitha S 


Timo
Replied On 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!

Timo

Farjana Parveen Ayubb [Syncfusion]
Replied On 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. 
 
Regards, 
Farjana Parveen A 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon