none
possible to change the query ?

    Question

  • Hi, when we do WCF RIA, those queries are generated automatically. Possible to modify them ? how and where  ?  Please advise. Thanks

    Thursday, April 05, 2012 4:57 PM

Answers

  • I have yahoo messenger. I will try to look at your skydrive

    Have a fun

    Friday, April 06, 2012 10:38 PM
  • Hi sdnd2000,

    Hi, when we do WCF RIA, those queries are generated automatically. Possible to modify them ? how and where  ?  Please advise. Thanks

    Yes. You can modify them.

    I have downloaded  your project and tested it locally. I found out that you didn't initialize the ProductID in the Home.xaml.cs. You need to initialize it at first and assign the value to it. Then use it as a parameter. 

    In addition, I have followed this Walkthrough below and created a demo.
     
     
    Then modified the query GetSalariedEmployeesbyQuery and uploaded it to skydrive. You can test it locally. 
     
    In the EmployeeList.xaml.cs, I have modified the code as follows:
     int ContactID = 1289;
                this.dataGrid1.ItemsSource = _OrganizationContext.Employees;
                _OrganizationContext.Load(_OrganizationContext.GetSalariedEmployeesbyQuery(ContactID));
     
    In the OrganizationService.cs
      public IQueryable<Employee> GetSalariedEmployeesby(int teststring)
            {
                return this.ObjectContext.Employees.Where(e => e.ContactID == teststring).OrderBy(e => e.EmployeeID);
            }
    Best wishes, 
    Monday, April 09, 2012 6:25 AM

All replies

  • Yes, you can intersept them and change as you wish.

    This code can be very helpful http://fknet.wordpress.com/2011/02/28/entity-framework-logging/

    Thursday, April 05, 2012 5:08 PM
  • Hi,

    Yes, You can modify at your DomainService. "how?"  and "Where" look at the following code. "how" is depend on your requirement, look at the code, I add GetProduct(int productID) to get one product by Silverlight Client project.

            #region GetProduct
            // TODO:
            // Consider constraining the results of your query method.  If you need additional input you can
            // add parameters to this method or create additional query methods with different names.
            // To support paging you will need to add ordering to the 'Product' query.
            public IQueryable<Product> GetProducts()
            {
                return this.ObjectContext.Product;
            }
    
            public IQueryable<Product> GetProduct(int productID)
            {
                return this.ObjectContext.Product.Where(p => p.ProductID == productID); ;
            }
    
    Thursday, April 05, 2012 5:32 PM
  • Hi, I just call GetProduct(productID) or GetProduct()? just tried both, and get error"Error    1    'Survey_Model.Web.Services.ProductDomainContext' does not contain a definition for 'GetProduct' and no extension method 'GetProduct' accepting a first argument of type 'Survey_Model.Web.Services.ProductDomainContext' could be found (are you missing a using directive or an assembly reference?) 


    Thursday, April 05, 2012 9:58 PM
  • It's must be deleted accidentially. If you do not have any manual changes yet it is not dificult to recreate it again, just create it again like you have done.

    Better backup your project frequently. We can not avoid this kind of problem, we can mimimize it.

    Happy coding 

    Thursday, April 05, 2012 10:26 PM
  • Tried  GetProductQuery(productID), still get error "Error    1    The name 'productID' does not exist in the current context   "
    "

    Thursday, April 05, 2012 10:36 PM
  • Hi,

    Means you do not have an entity dan have productID property. This is depend on what you need. The above code on my previuos reply is a sample to be your reference.

    Can you describe your project, what you have done, and if possible post your project or put it into Skydrive.

    Have fun

    Thursday, April 05, 2012 10:47 PM
  • Thanks. I just want to let those generated queries return a or some specific fields. The project I created is just to test which I have uploaded to my skydrive public folder. My id is sdnd2000@hotmail.com  Thanks

    Thursday, April 05, 2012 11:09 PM
  • Hi, Jsiahaan:

     

    I put a  function  like public int productID { get; set; }, still doesn't help

    Friday, April 06, 2012 2:45 PM
  • Hi,

    I am affraid we are not on the same topic. Where do you put "public int productID {get; set; }" it should be a column of a database table, in this case it is aproperty on an entity class. You give me your email address but I need your skydrive public address, so I can see what you have done, and try to help you. I can not see your skydreive by having email address. 

    Friday, April 06, 2012 7:07 PM
  • Sorry, here is the link : https://skydrive.live.com/?cid=7428fec4e719d2ff

    Friday, April 06, 2012 10:08 PM
  • Do you have email address or instant messenger so that we can talk directly. Thanks

    Friday, April 06, 2012 10:16 PM
  • I have yahoo messenger. I will try to look at your skydrive

    Have a fun

    Friday, April 06, 2012 10:38 PM
  • Hi sdnd2000,

    Hi, when we do WCF RIA, those queries are generated automatically. Possible to modify them ? how and where  ?  Please advise. Thanks

    Yes. You can modify them.

    I have downloaded  your project and tested it locally. I found out that you didn't initialize the ProductID in the Home.xaml.cs. You need to initialize it at first and assign the value to it. Then use it as a parameter. 

    In addition, I have followed this Walkthrough below and created a demo.
     
     
    Then modified the query GetSalariedEmployeesbyQuery and uploaded it to skydrive. You can test it locally. 
     
    In the EmployeeList.xaml.cs, I have modified the code as follows:
     int ContactID = 1289;
                this.dataGrid1.ItemsSource = _OrganizationContext.Employees;
                _OrganizationContext.Load(_OrganizationContext.GetSalariedEmployeesbyQuery(ContactID));
     
    In the OrganizationService.cs
      public IQueryable<Employee> GetSalariedEmployeesby(int teststring)
            {
                return this.ObjectContext.Employees.Where(e => e.ContactID == teststring).OrderBy(e => e.EmployeeID);
            }
    Best wishes, 
    Monday, April 09, 2012 6:25 AM
  • Hi, thanks for the help. It works . But it just returned the info that contactID = 1234, actually, I need the whole field including all the contract ID.

    Monday, April 09, 2012 9:37 AM
  • Hi,
    If you want to return the whole field including all the contract ID, you can do it as follows:

    In the EmployeeList.xaml.cs

         _OrganizationContext.Load(_OrganizationContext.GetSalariedEmployeesbyQuery());
                this.dataGrid1.ItemsSource = _OrganizationContext.Employees;

    In the OrganizationService.cs

     public IQueryable<Employee> GetSalariedEmployeesby()
            {
                return this.ObjectContext.Employees.OrderBy(e => e.EmployeeID);
            }

    Best wishes,

    Tuesday, April 10, 2012 10:42 PM