Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: How to work with InteractiveViews (Entity Framework 6.2)?

AllmanTool:

I try to use InteractiveViews nuget package to improve first query execution at my code first app.


namespace POC.UnitTests
{
[TestFixture]
public class EntityFrameworkViewCachingTests
{
private Stopwatch _watch;
private FileViewCacheFactory _veiwFactory;
private static string _path;

[OneTimeSetUp]
public void Setup()
{
_watch = new Stopwatch();
_connectionDictionary = new Dictionary()
{
{ 1, new SqlConnectionStringBuilder()
{
UserID = "UserId",
Password = "Password",
InitialCatalog = "MyDatabase",
DataSource = @"MyDb",
ConnectTimeout = 30,
MinPoolSize = 0,
MaxPoolSize = 100,
MultipleActiveResultSets = true,
}
};

_path = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\", "EFCache.xml"));
_veiwFactory = new FileViewCacheFactory(_path);

_watch.Start();

Start(() =>
{
using (var ctx = new ThickDbContext(_connectionDictionary[1].ToString()))
{
InteractiveViews.SetViewCacheFactory(
ctx,
_veiwFactory
);
}

Debug.WriteLine($"Work with cache consumed: {_watch.ElapsedMilliseconds} ms.");
});

_watch.Stop();
}

[Test]
[TestCase(1)]
public void QueryExecutionPerfomanceTest(int id)
{
// Arrange.
var sqlConnection = _connectionDictionary[id].ToString();

// Act.
_watch.Reset();
_watch.Start();

//Create dbContext, work with them and dispose it.
using (var dbContext = new ThickDbContext(sqlConnection))
{
var result = dbContext.RESOURCES.SingleOrDefault(r => r.RESOURCEID == id);

_watch.Stop();

//Fill dynamic DTO.
_info = new QueryDataDTO
{
Id = id,
DurationTime = _watch.ElapsedMilliseconds,
Source = typeof(RESOURCE).Name,
};

// Assert.
Debug.WriteLine($"id: {_info.id}. Duration: {_info.DurationTime} ms.");
}
}

private void Start(Action a)
{
// Sync.
a.Invoke();
}
}
}

I've been expected that pre-generation views will greatly impove perfomance at first query execution, but I get in general the equal results before and after generating EFCache.xml.

Also i read one post (http://ift.tt/2ra9KOW), but actually did not understand: Actually InteractiveViews works with EF 6.2 or not )

Both results (after and before view generation) show:


Work with cache consumed: 7518 ms.
id: 1. Duration: 3007 ms.

Thus, total time: 10.525


Work with cache consumed: 7363 ms.
id: 1. Duration: 1968 ms."

Thus, total time: 9.331

Q: Тhe difference is negligible ( ~ 13%) Where am I wrong with my implementation?

P.S I work with very big dbContext to get the more obvious result (482 Entities).



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: How to work with InteractiveViews (Entity Framework 6.2)?

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×