locked
Generic Error for lambda expression RRS feed

  • Question

  • User-1651183775 posted

    Hello,

    I am getting generic exception for my lambda expression. can anyone suggest me the option to troubleshoot this?

    Error:

    An exception of type 'System.Data.Services.Client.DataServiceQueryException' occurred in Microsoft.Data.Services.Client.dll but was not handled in user code

    InnerException: Null

    Expression:

    result= context.MyRequests.Expand("MyRecords").Where(r => r.DateModified > DateTime.Now.AddDays(-30)).ToList();

    Note: 1. Records exists in SQL table for this query.

    2. I have already set this property.

    context.IgnoreResourceNotFoundException = true;

    3. The query takes more than 2 minutes to execute in SSMS

    Wednesday, November 22, 2017 2:33 PM

All replies

  • Wednesday, November 22, 2017 9:27 PM
  • User-832373396 posted

    Hi <g class="gr_ gr_56 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="56" data-gr-id="56">kodnil</g>,

    Error:

    An exception of type 'System.Data.Services.Client.DataServiceQueryException' occurred in Microsoft.Data.Services.Client.dll but was not handled in user code

    I am trying to reproduce your error.

    At first, it seems that it doesn't exist .Expand() method in EF, so I guess that is .Except() method;

    Then, here is the testing code, everything is ok:

       class Person
            {
                public string FirstName { get; set; }
                public string LastName { get; set; }
                public System.DateTime mytime { get; set; }
            }
    
            class Pet
            {
                public string Name { get; set; }
                public Person Owner { get; set; }
            }
            public ActionResult Index()
            {           
                Person magnus = new Person { FirstName = "Magnus", LastName = "Hedlund" , mytime=DateTime.Now };
                Person terry = new Person { FirstName = "Terry", LastName = "Adams", mytime = DateTime.Now };
                Person charlotte = new Person { FirstName = "Charlotte", LastName = "Weiss" , mytime = DateTime.Now };
                Person arlene = new Person { FirstName = "Arlene", LastName = "Huff", mytime = DateTime.Now };            
    
                // Create two lists.
                List<Person> people = new List<Person> { magnus, terry, charlotte, arlene };
                List<Person> people1 = new List<Person> {  arlene };
                var result= people.Except(people1).Where(r=>r.mytime > DateTime.Now.AddDays(-30)).ToList();

    So, May I know your real data so that get the error point quickly?

    Please let me know if you have other information.

    With regards, Angelina Jolie

    Thursday, November 23, 2017 7:59 AM
  • User-1651183775 posted

    If there was no Expand() method it would have given me build error...right?

    Thursday, November 23, 2017 1:55 PM
  • User-832373396 posted

    <g class="gr_ gr_8 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="8" data-gr-id="8">Hi</g> <g class="gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="5" data-gr-id="5">kodnil</g>,

    f there was no Expand() method it would have given me build error...right?

    Yes. Could you tell me the .Expand() ?and you could F12 to go to definition.

    If it does in your EF framework, please tell me the namespace and full code <g class="gr_ gr_418 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="418" data-gr-id="418">of .</g>Expand() method so that I could reproduce the error on local ;

    Thanks,

    Angelina Jolie

    Friday, November 24, 2017 3:00 AM
  • User-1651183775 posted

    Could you tell me the .Expand() ?and you could F12 to go to definition

    //
            // Summary:
            //     Expands a query to include entities from a related entity set in the query response.
            //
            // Parameters:
            //   path:
            //     The expand path in the format Orders/Order_Details.
            //
            // Returns:
            //     A new query that includes the requested $expand query option appended to the
            //     URI of the supplied query.
            public DataServiceQuery<TElement> Expand(string path);
    Friday, November 24, 2017 6:36 AM
  • User-1651183775 posted

    Is it possible for someone to give me equivalent SQL query of this expression?

    Friday, November 24, 2017 8:19 AM
  • User-832373396 posted

    <g class="gr_ gr_9 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="9" data-gr-id="9">Hi</g> <g class="gr_ gr_8 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="8" data-gr-id="8">kodnil</g>,

    Please add context.IgnoreMissingProperties = true.

    Please have a try.

    kodnil

    Is it possible for someone to give me equivalent SQL query of this expression?

    and I found this official example(before, https://docs.microsoft.com/en-us/dotnet/framework/data/wcf/creating-the-data-service  ):

    private Uri svcUri = new Uri("http://localhost:12345/Northwind.svc");
     
        try
        {
            // Instantiate the DataServiceContext.
            context = new NorthwindEntities(svcUri);
    
            context.IgnoreMissingProperties = true;
    
            // Define a LINQ query that returns Orders and 
            // Order_Details for a specific customer.
            var ordersQuery = from o in context.Orders.Expand("Order_Details")
                              where o.Customer.CustomerID == customerId
                              select o;
    
            // Create an DataServiceCollection<T> based on 
            // execution of the LINQ query for Orders.
            DataServiceCollection<Order> customerOrders = new
                DataServiceCollection<Order>(ordersQuery);

    From https://docs.microsoft.com/en-us/dotnet/framework/data/wcf/creating-the-dotnet-client-application-wcf-data-services-quickstart 

    and reference:  https://docs.microsoft.com/en-us/dotnet/framework/data/wcf/how-to-load-related-entities-wcf-data-services 

    Hope it is helpful to you.

    With regards, Angelina Jolie

    Friday, November 24, 2017 9:07 AM
  • User-832373396 posted

    <g class="gr_ gr_8 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-ins replaceWithoutSep" id="8" data-gr-id="8">Hi</g> <g class="gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="5" data-gr-id="5">kodnil</g>,

    Is it possible for someone to give me equivalent SQL query of this expression?

    Sir, I found this.

    OData also enables you to address resources based on the results of query expressions. This makes it possible to filter sets of resources based on an evaluated expression. For example, the following URI filters the resources to return only the Orders for the specified Customer that have shipped since September 22, 1997:

    http://services.odata.org/Northwind/Northwind.svc/Customers('ALFKI')/Orders?$filter=ShippedDate gt datetime'1997-09-22T00:00:00'

    And 

    $filter Defines an expression that filters the entities returned in the feed based on specific criteria. This query option supports a set of logical comparison operators, arithmetic operators, and predefined query functions that are used to evaluate the filter expression. The following example returns all orders the postal codes of which do not end in 100:

    http://services.odata.org/Northwind/Northwind.svc/Orders?$filter=not endswith(ShipPostalCode,'100')

    For more information, see OData: Filter System Query Option ($filter).
    $expand Specifies which related entities are returned by the query. Related entities are included as either a feed or an entry inline with the entity returned by the query. The following example returns the order for the customer 'ALFKI' along with the item details for each order:

    http://services.odata.org/Northwind/Northwind.svc/Customers('ALFKI')/Orders?$expand=Order_Details

    From https://docs.microsoft.com/en-us/dotnet/framework/data/wcf/accessing-data-service-resources-wcf-data-services 

    Hope it is helpful to you.

    With regards, Angelina Jolie

    Monday, November 27, 2017 2:37 AM