I have problems with the time when EF pulls some objects. The entity in question has a boat of details that live in 1 table, but also has several ICollection that relate to other tables. I gave up the idea of loading an entire graph of objects, since that is too much data, and instead, my Silverlight client will send a new request to my WCF service as needed.
After you lose weight to 1 tablespoon thing, it takes about 8 seconds to pull out the data, and then another 1 second to .ToList () (I expect it to be <1 second). I use the stopwatch class to measure. When I run the SQL query in the SQL management studio, it only takes a fraction of a second, so I'm sure the SQL query itself is not a problem.
This is how I try to request my data:
public List<ComputerEntity> FindClientHardware(string client) { long time1 = 0; long time2 = 0; var stopwatch = System.Diagnostics.Stopwatch.StartNew();
I assume that using .Include means impatient loading, although in my current case this does not matter, since I just need 1 tablespoon of material. The SQL generated by this statement (which runs super fast in SSMS):
SELECT [Extent1].[AssetID] AS [AssetID], [Extent1].[ClientID] AS [ClientID], [Extent1].[Hostname] AS [Hostname], [Extent1].[ServiceTag] AS [ServiceTag], [Extent1].[Manufacturer] AS [Manufacturer], [Extent1].[Model] AS [Model], [Extent1].[OperatingSystem] AS [OperatingSystem], [Extent1].[OperatingSystemBits] AS [OperatingSystemBits], [Extent1].[OperatingSystemServicePack] AS [OperatingSystemServicePack], [Extent1].[CurrentUser] AS [CurrentUser], [Extent1].[DomainRole] AS [DomainRole], [Extent1].[Processor] AS [Processor], [Extent1].[Memory] AS [Memory], [Extent1].[Video] AS [Video], [Extent1].[IsLaptop] AS [IsLaptop], [Extent1].[SubnetMask] AS [SubnetMask], [Extent1].[WINSserver] AS [WINSserver], [Extent1].[MACaddress] AS [MACaddress], [Extent1].[DNSservers] AS [DNSservers], [Extent1].[FirstSeen] AS [FirstSeen], [Extent1].[IPv4] AS [IPv4], [Extent1].[IPv6] AS [IPv6], [Extent1].[PrimaryUser] AS [PrimaryUser], [Extent1].[Domain] AS [Domain], [Extent1].[CheckinTime] AS [CheckinTime], [Extent1].[ActiveComputer] AS [ActiveComputer], [Extent1].[NetworkAdapterDescription] AS [NetworkAdapterDescription], [Extent1].[DHCP] AS [DHCP] FROM [dbo].[Inventory_Base] AS [Extent1] INNER JOIN [dbo].[Entity_Company] AS [Extent2] ON [Extent1].[ClientID] = [Extent2].[ClientID] WHERE [Extent2].[CompanyName] = @p__linq__0
Basically it is to select all the columns in this table, join the second table with the company name and filter using the where clause for file_name == for the method. The special company I pull out returns only 75 records.
Disabling object tracking using .AsNoTracking () has zero effect on runtime.
I also gave the Find a go method and had the exact runtime. The next thing I tried was to recreate the views if the problem was there. I use the code first, so I used the EF power tools for this.
This long period of time to run this request causes too much delay for my users. When I write SQL code and not touch EF, it is very fast. Any ideas on what I am missing?
It may also be related or not, but since I am doing this in WCF, which is stateless, I assume that absolutely nothing is cached? The way I think about this is that every new call launches this WCF service library for the first time, so there is no existing cache. Is this an accurate guess?
Update 1
So I ran this query twice in the same unit test to check the cold / warm request. The first request is terrible, as expected, but the second is lightning fast, in just 350 ms. Since WCF has no status, will every call to my WCF service be treated as this first ugly slow request? Still need to figure out how to get this first request, so as not to suck.
Update 2
Do you know the preliminary ideas that I mentioned earlier? Well ... I don’t think they were hit. I set a few breakpoints in the ReportingDbContext.Views.cs file with auto-generated EF-powertools, and they never hit. This combined with the cold / warm requests that I see, it sounds as if it could be meaningful. Is there any specific way I need to preview the views using the EF power tools in the first code environment?