Very first query to dbcontext takes very long time. I did some search and found that for the first call there is metadata calculation which takes time. Solution suggested was to use entity framework powertools to generate pre complied views. I tried this but is was of no use.
Did anyone get any solution for this?
Thanks,
Related
I am newbie in Entity framework. In my application I have so many tables. I have just implemented CRUD for one module i.e. (For UserMaster). Now I have to implement same for other modules as well.
Can you please tell me should i used only one .edmx file for all the tables or different .edmx file for different module will work?
I search a lot on internet... and they suggest to use different files... but I dont know how to use it... Also I didn't get any sample example for this...
Can you please help me????
You should use multiple diagrams per model in Entity Framework >= 5.0
http://weblogs.asp.net/dotnetstories/using-multiple-diagrams-per-model-in-entity-framework-5-0
Otherwise, another way is to completely get rid of edmx file which is far better with the help of code first.
This might be a weird question to ask.. but nevertheless this is my question.
I have a huge Asp.net MVC project with lots of model classes. As the requirement grew, we kept on adding some properties and deleting some. Eventually I ended up having properties which are not referenced anywhere in the project.
Is there any quick way to find out these orphan properties.?
ReSharper can do this. Right-click on your solution and selection "Find Code Issues".
One of the results is "Unused Symbols". This will show you classes, methods, properties etc., that aren't used.
I would use resharper to assist you with this task. In case you don't want to spend the $349 you can use it for 30days for free. Resharper allows you to analyse the whole solution and highlights obsolete/unused code.
Yes, I've read the warning label, and I know that dynamically loading assemblies is somewhat discouraged. That said, I have an application that loads assemblies - that's just how it works. It works fine on Windows. Works fine on Windows CE. I need it to "work fine" on Android, even if it takes some massaging.
Basically the app is an engine that loads up plug-in DLLs (we'll call it an Adapter) that meet specific interfaces at run time. Under Windows, it even detects the appearance of a DLL at any point and goes and loads it - I'm fine if that's not going to work under Android.
What I'm having trouble getting working is having the Engine load an Adapter that it knew about at design/compile time but without hard coding the name of that Adapter into the Engine code. I'm fine with adding a reference to the Adapter to get it to not get linked out, but I really, really don't want to have to add in the DLL name every time, as the DLLs change with different deployments, and that would lead to a huge headache.
So I figured that if it's referenced, it would get into the APK, and I could use reflection to load it like this:
var asm = Assembly.Load("TheAdapterName.dll");
Initial tests show that this works for the Adapter if I just hard code in the name, but again, I really, really want to avoid that.
So I thought that maybe I could reflect through the references and extract the name, but oddly, not all references actually show up when I do that. So I do this:
var refs = asm.GetReferencedAssemblies().Select(a => a.Name).ToArray();
And I get back an array of 14 assembly names. But the assembly (asm) has 16 references, one of which is the Adapter plug-in I need to load. The Adapter is definitely there - heck I used Assembly.Load with the full name two lines above and it resolved.
I thought, ok, maybe I can figure out the "path" to the folder from which I'm running, and then look for DLLs there and load that way. Ha. After several hours of trying to figure out a way to get the path that would work under Debug and Release, I came up with nothing but more grey hair.
Sooooo...... any thoughts on how I might get the name of a DLL that I know is in my APK, but that I don't "know" the name of at build time (I'm loading them and looking for interfaces via reflection to detect their "Adapterness").
If those methods aren't working for you, then the only suggestion I can think of is to add a prebuild step which updates either a C# or an Assets file in order to provide the list you need.
Obviously this is extra work, but should be fully automated and is guaranteed to work no matter what platform changes get thrown at you.
As an aside, I also just looked at one of my mvx projects using reflector - it shows the same asm.GetReferencedAssemblies() list as your investigations report - runtime-loaded plugins are not listed. I guess that the GetReferencedAssemblies method is reporting only on assemblies actually used to import Type references at the IL level - so if you reference an assembly in the csproj but don't import any types then it doesn't list them as references in the compiled code.
This issue is becoming a nightmare for me, especially, after days of research there is nothing in favor.
The problem is that, some of the navigation properties are lost.
Please check this for code details
I am using Entity framework with repository pattern, and also have tried out setting "SetMergeOption" to "NoMerge" for Objectset but this didnt help either
I got them working after updating POCO generator to use EF version 5.0
I've been struggling with this for a while now, and I see that I'm not the only one with the problem (see this and that).
I've managed to debug for a bit, and found a solution, though I'm pretty sure that this is not the 'right' way.
The first debug session (before the dev server was enabled) showed that the ProfiledDbConnectionFactory and ProfiledDbConnection classes provide the required data, but then AFTER the connection is created, the static Instance property on ProfiledDbProviderFactory is initialized (by calling the default constructor) and apparently CreateConnection() is run on that instance resulting with a null reference exception (tail is null).
I've managed to solve this by running
ProfiledDbProviderFactory.Instance.InitProfiledDbProviderFactory(_profiler, ripInnerProvider(_conn));
at the end of ProfiledDbConnection(DbConnection connection, IDbProfiler profiler).
This allows me to view the sql profiling, but as I wrote, I have a feeling that this isn't the correct fix.
Here's the sample code I used.
Not sure if there is something wrong with my environment, or my code, as I have a feeling that this should work out of the box. Any comments/suggestions?
Sam?
there is nothing wrong with using ProfiledDbConnectionFactory entity framework is designed to support ignorance i generally just use the debugger tools and create a breakpoint to view my generated sql statements as the code first framework provides the sql statement readily there
i would stick to using profiled connections the way you described in your unit testing as opposed to using it in production code as the profiling may be a performance hit you way also want to consider using the sql profiler included in sql server and there is also an sql profiler available as a visual studio extension however i am not sure if it supports code first as of yet
This problem has been resolved in version 1.9.1 of MiniProfiler.EF