[Solved] Can someone help me find the bottleneck in this code?

That’s because allLogs is lazy in nature — it will actually hit the database when first enumerated through in the foreach (see “Deferred query execution” here). If you materialize the collection before hand like the following, you will see that it steps through the foreach quickly: db.StatusLogs .Where(sl => sl.ID.Value.Equals(foo)) .GroupBy(sl=>sl.bar) .ToList(); // <– pull … Read more

[Solved] New class object error : Object reference not set to an instance of an object [duplicate]

This is your problem: _cache.TryGetValue(“CountsStats”, out countStats) out will change the object that countStats is pointing to. If it’s found in the cache, then it will be the cached object. Great! If it isn’t, then it will be null. You need to create a new instance in this case. You should change your code to … Read more

[Solved] How to convert linq query to non-query expression?

If you want to convert this to the method syntax version, you can do this step by step. I like to start at the end and work through to the beginning: select to Select defines the source: .Select(g => g.OrderByDescending(s => s.MeasureDate).FirstOrDefault()); group is GroupBy: .GroupBy(s => s.SensorUnitId) .Select(g => g.OrderByDescending(s => s.MeasureDate).FirstOrDefault()); from the … Read more

[Solved] Seeking feedback on my design of LINQ expressions [closed]

You’re comparing apples and oranges. Each of the approaches you list has benefits and drawbacks, so it’s impossible to answer which is the “preferred way.” Likewise, many of these examples will return immediately because they use deferred execution, so they’ll technically run faster, but won’t actually make your program run any faster. But if you’re … Read more

[Solved] “Member Mapping specified is not valid” error when saving to a database with Entity Framework

The error message is pretty clear: The type ‘Edm.String’ of member ‘SEJ_STARDATE’ in type ‘HotelSearch.APP_SEJOUR’ is not compatible with ‘SqlServer.date Change edm.String to a recognizable datetime format (MM/DD/YYYY) by manipulating its contents or using DateTime.Parse solved “Member Mapping specified is not valid” error when saving to a database with Entity Framework

[Solved] Class Library (.Net Framework) not supporting Entity Framework

Finally, I found solution to this. When I install Entity Framework, EF places some default code in application’s config file. As below: Problem Code: <defaultConnectionFactory type=”System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework”> <parameters> <parameter value=”mssqllocaldb” /> </parameters> </defaultConnectionFactory> Solution: This was root of the problem I was facing. By default it was creating a local connection string for itself. I … Read more

[Solved] I am try to Pagination using Skip Take in Code Frist Approach But given Error

[HttpPost] [Route(“Paging”)] public async Task <ActionResult<IQueryable<City>>> Paging(int CurrentPage=1) { var abc= await _dropdowncontext.cities.OrderBy(x=>x.CityId).Skip((CurrentPage – 1) * 5).Take(5).ToListAsync(); if (!abc.Any()) return NotFound(); return Ok(abc); } 1 solved I am try to Pagination using Skip Take in Code Frist Approach But given Error