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);
Related
Having issues using EFProf (http://www.hibernatingrhinos.com/products/EFProf) with ASP Boilerplate (http://www.aspnetboilerplate.com/).
For unit testing, ASP Boilerplate uses Effort (https://github.com/tamasflamich/effort) for mocking the database in-memory.
If I run the unit tests without adding the reference to EFProf, the tests run correctly (green).
If I add the initialization line:
HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();
in either my test base ctor or my application project's Initialize(), I get the following error:
Castle.MicroKernel.ComponentActivator.ComponentActivatorException
ComponentActivator: could not instantiate MyApp.EntityFramework.MyAppDataContext
The inner exception has the relevant information:
Error: Unable to cast object of type 'Effort.Provider.EffortConnection' to type 'HibernatingRhinos.Profiler.Appender.ProfiledDataAccess.ProfiledConnection'.
Is Effort just not compatible with EFProf? Or am I doing something blindingly obvious wrong in my initialization?
Answering my own question: Effort fakes the DbContect object but does not actually create SQL for in-memory, thus there is nothing to intercept by profilers. It is also the reason why the CommandText is always null when using EF6's Database.Log with Effort.
Am going to try using Moq with EF6 to use an in-memory database implementation for testing as an alternative to Asp Boilerplate's testing project that utilizes Effort per this article: https://msdn.microsoft.com/en-us/library/dn314429(v=vs.113).aspx
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.
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).
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/
I'm working on an MVC site using EF4 as my data source. I've had no problems with other projects with EF4 until today. I'm getting an error stating EntitySet name Entities.Sites could not be found. I have another EDMX file for another dataset that is set up nearly the same (with different entity names) and it works fine when I try to run a LINQ query against it.
My EDMX has 2 tables (site and page) with a 1 to many association from the site to page table. Everything compiles fine, but in runtime, it's almost like the datamodel fails on every property list population. I do have Lazy Loading enabled (It's a .NET 4 project).
I stepped through the code on the designer class and it fails when it gets to a call like this
if((_Pages == null))
{
_Pages = base.CreateObjectSet<Page>("Pages");
}
I have not altered the code in the designer.cs. I'm at a major wall with this.
Any ideas what I could be doing wrong?
Try renaming your entity Page to something else, like EntityPage (for example) to see if this resolved it. As stated by #Yakimych this could simply be a case of Namespace clashing