locked
QueryCreated with join RRS feed

  • Question

  • User-2085110706 posted

    Hi. I'm working with VS2012 .net 4.5 EF5

    i want to use a join in a QueryCreated event, but i am not able to do it.

    I want that this code

     

        protected void GridDataSource_QueryCreated(object sender, QueryCreatedEventArgs e)
        {
            DateTime _data = DateTime.Parse(TextBoxDataRegistroDiClasse.Text);
            int _idClasse = int.Parse(DropDownListClassi.SelectedItem.Value);
            var righe = e.Query.Cast<Registro_di_classe>();
    	e.Query = from riga in righe
    
                   
                      where
                      riga.ID_Classe_collegata == _idClasse
                      &&
                      riga.Data_registro_di_classe ==_data 
    
                      select riga;
    	}

    Become

     Segremat8Entities _segremat8=new Segremat8Entities();
            DateTime _data = DateTime.Parse(TextBoxDataRegistroDiClasse.Text);
            int _idClasse = int.Parse(DropDownListClassi.SelectedItem.Value);
            var righe = e.Query.Cast<Registro_di_classe>();
    
    
    
            e.Query = from riga in righe
    
                      join classi in _segremat8.Classi
                      on riga.ID_Classe_collegata equals classi.ID_Classi
                   
                      where
                      riga.ID_Classe_collegata == _idClasse
                      &&
                      riga.Data_registro_di_classe ==_data 
    
                      select riga;

    But it does't work. In what way i can use a Join in a QueryCreated event?

    Tuesday, November 27, 2012 6:44 AM

Answers

  • User3866881 posted

    If you wanna do something complicated, I think you can just remove EntityDataSource but manually do data-binding.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 28, 2012 3:20 AM

All replies

  • User3866881 posted

    Hello,

    As far as I see, Occurs after the EntityDataSource creates an Entity SQL query that was specified during the configuration of the EntityDataSource control.

    In fact you can see this sample:

    http://msdn.microsoft.com/en-us/library/ee404748.aspx

    Tuesday, November 27, 2012 8:33 PM
  • User-2085110706 posted

    Yes I saw the sample, but i need to make a join for a where cause. Is it possible in some way?

    Wednesday, November 28, 2012 3:04 AM
  • User3866881 posted

    but i need to make a join for a where cause. Is it possible in some way?

    Where do you wanna add a "where"?

    Wednesday, November 28, 2012 3:08 AM
  • User-2085110706 posted
    e.Query = from riga in righe
    
                      join classi in _segremat8.Classi
                      on riga.ID_Classe_collegata equals classi.ID_Classi
                   
                      where
                      riga.ID_Classe_collegata == _idClasse
                      &&
                      riga.Data_registro_di_classe ==_data
     && classi(JOINED TABLE).Name="name"
    
                      select riga;

    I want to make a where in the joined table value (or will join 6 tables and add a where in the table 6)

    Wednesday, November 28, 2012 3:16 AM
  • User3866881 posted

    If you wanna do something complicated, I think you can just remove EntityDataSource but manually do data-binding.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 28, 2012 3:20 AM