In EF6 we have DbPropertyValues inside System.Data.Entity.Infrastructure
I am trying to migrate a EF6 library to .net Core. I have done most conversions, but I can't find an equivalent to DbPropertyValues which I use when comparing changes of an entity. What can I use instead? Is there an equivalent to System.Data.Entity.Infrastructure?
Related
In our company we have a lot of legacy applications which use an edmx file together with EF4.
We would like to migrate to EF6 (or EF core). Is there a way that we can generate the code first objects (dbcontext, entities) from this edmx with the mappings.
How can we do this?
Maybe the best solution for this will be scaffold (reverse engineer your model) from current database.
EF Core has nice powershell tools for this scaffolding https://learn.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db
You can also split the whole (maybe big) DbContext to more DbContexts with specified Table parameter
https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell
EF 6 has also some options for scaffold actual database Entity Framework - Generating Classes
Why would you bother generating anything from .edmx? What if you created new project with code first from existing database?
I want to know your opinion.
In scenario, where only stored procedures are used for data manipulation - is better to use standard ADO.NET or Entity Framework 5.
The only (and main) reason for using EF are strongly typed classes (generated complex classes), that can be used as a model in ASP.NET MVC 4. Updating complex types could be simpler in EF compare to ADO.NET.
Reason for using ADO.NET is making communication with database more simply.
Thank you for your opinion.
You could also look at e.g. Dapper-Dot-Net (or some of the other "micro-ORM") which is based off "raw" ADO.NET, but also offers conversion to nice .NET objects (the main EF benefit in your case, I believe) from stored procedure results
Does anyone know why LinqPad cannot autogenerate an Entity Framework context object (like it does with Linq-to-SQL)? It seems I have to create an assembly containing an EF context and then reference the assembly in LinqPad. But I don't need to do this with L2S.
Thanks very much.
LINQPad uses LINQ-to-SQL for automatic data contexts because it's lighter and faster. LINQ-to-SQL also generates better SQL in many cases and allows arbitrary functions in the final projection.
It wouldn't be hard, in principle, to write a driver for Entity Framework. The reason it isn't present as an option is lack of demand.
If you wanted, you could implement EF support seamlessly as a third-party driver. The only tricky thing to implement is supporting every version of EF.
EF and ORM.
I recently realized that is possible using POCO to have clean classes not plumbed with EF auto generated code.
I saw the new release of EF 4.1 and the use of Code First approach and DbContext.
My questions:
What is the difference between Code First approach and Poco approach?
Can we use Code First (DbContext and DbSet) instead of POCO + Repository pattern?
Thanks for your time on this.
They're completely different things, and you can use them together.
POCO means that your entity classes are "normal" classes, not dependent on any specific ORM layer.
A DbContext is an object that enables you to access the database in an object-oriented way (like ObjectContext in earlier versions of EF).
Have a look at this tutorial for examples.
I am encountering some performance problems with my Entity Framework Code-First queries and I believe that precompilation may be the answer. If I were using "normal" Entity Framework, I would simply use the CompiledQuery.Compile method to precomiple my queries. But since I have a DbContext and not an ObjectContext, I can't get this to work.
I do realize that DbContext is an IObjectContextAdapter, which gives me access to the ObjectContext, but I cannot find the method that lets me get an IQueryable from my object context that works in my precompiled query. I tried to use CreateObjectSet, but when EF tried to run the query it complained that it couldn't convert that method into SQL.
So what is the best way to precompile LINQ queries against a Code-First DbContext?
This will be probably solved in EFv4.2 EF vNext (currently in the very first CTP) by auto-compiled LINQ queries.
As from the official announecment:
"No compiled query support from DbContext
Unfortunately due to some technical limitations in the compiled query functionality we shipped in .NET Framework 4.0 we are unable to support compiled queries via the DbContext API. We realize this is a painful limitation and will work to enable this for the next release. "
Link.