InsertHistoryOperation throws InvalidOperationException while no Database is existing - entity-framework

i have big Trouble using the EntityFramework 5.0. After updating EF in our Project from EF4.2 to EF5.0. The Framework throws InvalidOperationExceptions in the TypeInitializer of InsertHistoryOperation during initializing of the database. (In the InnerException it says: "The List does not contain any element").
I tried using DropCreateAlwaysInitializer as well as DropWhenModelChanges. We don't need the Migration Feature (Sure, would be nice to have, but not recommend). Is there a way to disable the Migration Feature so the exception is not thrown. Or can somebody give me a hint what i did wrong?
The Model is very complex, so i think its not very useful to post it here.
best regards,
Chris
I tried with .Net4.0 and .Net4.5

Ok, i got it.
The Problem is that the EntityFramework since V5.0 is not able to work correctly if you merge it into (e.g. a Datalayer Assembly) or use it from a merged assembly. (ILMerge).

Related

AutoMapper EF6 ProjectToList<T> "Method not found"

I'm using the Automapper (v10) and Automapper EF6 (v2) library for the first time (I've used AutoMapper successfully before) with EF6.4 and I'm getting a weird issue with the following line of code
using (DashboardEntities db = new DashboardEntities())
return db.Dashboards.ProjectToList<DTO.Dashboard>();
Really just want to get all entities from the DB, but mapped to DTO objects so I can keep the UI and Data projects distinct and not have an EF6 reference in my UI project.
The above snippet builds but throws a runtime exception:
System.MissingMethodException: 'Method not found: System.Linq.IQueryable`1<System.__Canon>
AutoMapper.QueryableExtensions.Extensions.ProjectTo(System.Linq.IQueryable,
System.Linq.Expressions.Expression`1<System.Func`2<System.__Canon,System.Object>>[])
The documentation gives an example using an Async version of the above method, but in my scenario, I don't want this.
I don't get why I'm getting this MissingMethodException at runtime
I could use the basic Automapper library and add some lines of code, but that defeats the purpose of the AutoMapper EF6 plugin and also reminds of this blog post I saw a while back
Thanks in advance for any insights
In the ProjectToList method, try to pass in the IConfigurationProvider. For example:
db.Dashboards.ProjectToList<DTO.Dashboard>(Mapper.ConfigurationProvider);

EF - Eager include grandchildren not working, does not contain definition for 'Select'

I am working in VS 2015 solution with an MVC 5 project and a code library project using EF 6.1. I have redone the entire project from a previous version in VS 2013 hoping it would resolve this problem, but no luck. I am just trying to eager load a child with grandchildren. I tried this:
Test t = db.Tests
.Include("TestsRemoteOBD")
.Include("TestsRemoteOBD.TestsRemoteOBDDtcs")
.FirstOrDefault();
and this:
Test t = db.Tests
.Include(i=>i.TestsRemoteOBD)
.Include(i=>i.TestsRemoteOBD.Select(s=>s.TestsRemoteOBDDtcs))
.FirstOrDefault();
Include using the string works for the child, but not the grandchildren. And with the 2nd query, I'm getting this error:
'TestsRemoteOBD' does not contain a definition for 'Select' and no extension method 'Select' accepting a first argument of type 'TestsRemoteOBD' could be found (are you missing a using directive or an assembly reference?)
I've seen the same question resolved by adding "using System.Data.Entity;", but I had done that a long time ago. No help. What else could I be missing?
Thanks!
Thanks so much, to all those who commented. I would have been banging my head for another day, at least. The way I had written the second statement would have worked fine if the parent [Tests] had a 1-to-many relationship with [TestRemoteOBD], but since the latter was not a collection, there was no 'Select' defined. I have not tested, but I believe it should be something like:
Test t = db.Tests
.Include(i=>i.TestsRemoteOBD)
.Include(i=>i.TestsRemoteOBD.TestsRemoteOBDDtcs)
.FirstOrDefault();
Bump. Found this and thought I'd throw in my own research.
Microsoft's
Documentation
states: To include a reference and then a reference one level down: query.Include(e => e.Level1Reference.Level2Reference)
-- but this doesn't seem to work under even the simplest use case. Executing the query with a .ToList() does not actually include anything. Smells like an obvious bug to me!
I can see 2 workarounds.
First, as Ben here suggests, you can manually iterate over the entities to force EF to load them.
Second, if scoping permits, you can forget the 'using' block and keep a more permanent instance of the dbcontext as a class member so that it's still available, not disposed (System.ObjectDisposedException), when the members are accessed.

EntityCommandExecutionException with EF 6 in project net 4.0?

I have using entity framework 6 in a project that is net 4.0, and when I instaled the nuget package, the project adds the reference to EntityFramework.dll and EntityFrameWork.SqlServer.dll.
However, I want to capture the exception EntityCommandExecutionException, but there is not avaliable in neither of the both dlls.
I know that I can add a reference to System.Data.Entity, but I don't konw if this a good solution, because when I try to use the enum EntityState there are a conflict because the are one in the System.Data.Entity and other in EntityFramework.dll.
So the quiestion is if it is a good idea to use the System.Data.Entity library with EF 6. And if it is a bad idea, which is the equivalent exception of EntityCommandExecutionException in EF 6?
Thanks.
EF6 does not use System.Data.Entity.dll so adding a reference to this assembly won't help since EF6 will throw its own EntityCommandExecutionException. Actually adding a reference to an EF6 project will create even more confusion since the two are not designed to work together even though the type names tend to be called the same (EF6 was build by merging System.Data.Entity.dll and EntityFramework.dll code bases but is not binary compatible with EF5). In your app you need add
using System.Data.Entity.Core;
since this is where the EntityCommandExecutionException type lives in EF6.

Doctrine 2.1 abstract entity, validation using annotations

My name is Denis and I really need your help or advice or anything :)
I am developing my project in Zend Framework 1.11 and am using Doctrine 2.1.
I have successfully integrated Doctrine in my ZF project and everything works. I also integrated Gedmo extensions and some my custom extensions.
The problem is with validation. I want to have validation of doctrine entities by using annotations. Because I sometimes need to validate my entities sometimes don't, I want that sort of validation, for example:
$user = new Entity\User; $user->setName('user'); $user->validate();
I don't want to change doctrine generated entities at all, so I won't change setters or use doctrine events for this.#HasLifecycleCallbacks.
I run into example at http://www.spiffyjr.me/2011/07/15/more-doctrine-2-and-zend-framework-integration-goodies/.
I downloaded code but didn't managed to put it in work. I followed instructions from that page, made my entities extend AbstractEntity, but when try to use for example isValid() i recieve following error:
[Semantical Error] The annotation "#Column" in property Bild\Entity\TestTest::$id was never imported. Did you maybe forget to add a "use" statement for this annotation?
I use doctrine annotations without #ORM\, just #, (for example #Column, not #ORM\Column). I even tried to add ORM but no luck it continues to throw errors.
I can recieve metadata for my entity, get field mappings and associating mappings, but when I try to getPropertyAnnotation
// validator annotations
$vAnnotations = self::_getPropertyAnnotation($property, self::ZENDVALIDATION);
var_dump($vAnnotations);die;
I recieve mentioned semantic error.
I tracked the errors down to Doctrine\Common\Annotations\AnnotationReader::getPropertyAnnotations($property); not returning annotations but throwing errors.
What do you think it can be?
It seems like I am not doing something properly but can't figure out what.
So, I need to make abstract entity, make my entities extend it, and make functions to validate my entities by using annotations.
So please, help me with this, if you can. I really need for my project but couldn't find a solution.
Thanks in advance.
Best regards.
The problem is caused by the configuration of the annotation reader. I went through the same problems while integrating the Symfony2 validator service for my Doctrine2 models in ZF1, more on the blog post here http://ssmusoke.wordpress.com/2012/03/04/doctrine-2-day-2-model-validation-using-symfony-validator-service-in-zend-framework/

Changing the core data model versionIdentifier

I'm trying to debug an issue with my mapping model not being used by my migration, and so I printed out the sourceModel and destinationModel's versionIdentifiers, but both were blank.
http://developer.apple.com/library/ios/#documentation/cocoa/Reference/CoreDataFramework/Classes/NSManagedObjectModel_Class/Reference/Reference.html%23//apple_ref/occ/instm/NSManagedObjectModel/versionIdentifiers
This link says to set them in the model inspector but I can't find that on xcode 3 or 4... or at least there is no versionIdentifier or similar in anywhere I can find for the data model itself.
Does anyone know where I find that?
Take a look at this posting - and, in particular, my answer ;) : Core Data lightweight migration: Can't find or automatically infer mapping model for migration
I did not find versionIdentifiers to be as helpful in debugging as the 'metadata' for the various entities - as I outlined here: NSManagedObjectModel versionIdentifiers
Hope this helps.