Entity Framework 6 with Sql Server Compact 3.5 SP2? - entity-framework

I have found lots of information about using Entity Framework 6 with Sql CE 4 and on using Entity Framework 4 with both Sql CE 4 and 3.5, but using Entity Framework 6 with Sql CE 3.5 is a different matter. As far as I can tell, CE 3.5 ships with a provider for Entity Framework 4 in System.Data.SqlServerCe.Entity.dll. This provider uses an older version of the base classes and if I try to use it, I get the following exception:
System.InvalidOperationException: The 'Instance' member of the Entity Framework provider type 'System.Data.SqlServerCe.SqlCeProviderServices, System.Data.SqlServerCe.Entity, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
This makes sense and points me to the realization that what I need is a provider for Entity Framework 6 for Sql Server CE 3.5 SP2. I can't seem to find such a thing though. The nuget package EntityFramework.SqlServerCompact seems to only reference Sql Compact 4 in all its versions. Does such a provider already exist? If so, where can it be found? I seem to be having difficulty locating it. If not, would it be realistic to think of implementing it by using the code in the one for CE 4 with a reference to 3.5, or is the difference between CE 3.5 and 4 too different for that to be straightforward? Is there another workaround?
I need to use 3.5 because of a need for using merge replication, which is not supported in 4, and would like to use Entity Framework. If there's not a straightforward answer to this, I'll probably use something other than Entity Framework.

OK, this is the second request I hear for this, let us do it. I will fork the code, and make a Nuget package for 3.5 - how about "EntityFramework.SqlServerCompact.Legacy" ? The "only" code change required is the fact, that 3.5 does not support ORDER BY..FETCH..OFFSET syntax (ie paging) called via Take and Skip. Would you be interested in this?
UPDATE: Package now available on NuGet http://www.nuget.org/packages/EntityFramework.SqlServerCompact.Legacy

Related

Is Entity Framework 6 used code first approach only?

Is Entity Framework 6 uses code first approach only ? I am a bit confused when we talk about code first approach, but i want to know if it works only with entity framework 6 or entity framework 6 uses code first approach only?
No, EF 6 does not ony support Code First. Code first can be a confusing name. It does not mean that you write code and then generate a db from that. You could in fact both target a new or an existing database using code first strategy. Code first simply imply not using the model designer (edmx) to create and maintain your db-context in your development project.
Some links to get you going:
EF 6 Database first (with asp.net mvc)
EF 6 Code first against new db (with asp.net mvc)
EF 6 Code first against existing db
Ps. Worth noting is that EF 7 (Core) will only support the Code First approach (but of course, as in EF 6, against a new or an existing db).
Checkout this links to find the Different approach of Entity Framework,
Basically we have 3 approach in that,
Code-First
Code First(Reverse Engineering) development targeting an existing
database.
simple-code-first-example
Model-First
model-first-with-entity-framework
Database-First
database-first-with-entity-framework

DBContext cache expression tree of a query

I'm actually working on a project who use a very big linq to entity query (around 250 lines) who works with a lot of different entities.
This query depend of few parameters (3 or 4 max) so I think to "store" the expression tree of my query and modifying this one with just my few parameters like this.
IQueryable<Foo> myQuery =
GetBaseQuery()
.Where(a => a.Param1 == "foo")
.Where(a => a.Param2 == "bar");
Apart using compiled queries, is there a way to do that ?
This problem has some conditions
I use DbContext and changing to ObjectContext is difficialy possible and it seems that this is a pre requities for using compiled queries.
I use Visual Studio 2010 so... i'm limited to .NET 4 and entity framework 4.3 (no .NET 4.5, EF5 and autocompiled queries unhopefully)
So, Is there a way to
Store an expression tree who will be just used as a "base" and will not take too much time to be generated ?
Or using .NET 4.5 in visual studio 2010 ?
Or using Compiled queries with a DbContext
REALLY Thank's by advance !!!
Reading between the lines, it seems you want compiled queries with DbContext. (This isn't really the same as storing the LINQ expression tree, but that doesn't seem to be the performance bottleneck in the testing we have done anyway.) As far as I know the options you have are:
Use EF5 with .NET 4.5. Even if you are using VS2010 and targeting .NET 4 if you install .NET 4.5 on the machine where the app is run then you will get auto-compiled queries.
Use EF6 with .NET 4 or .NET 4.5. EF6 moves the auto-compiled query code out of the .NET Framework so it gets used even when running on .NET 4.
Use ObjectContext and CompiledQuery
I'm not aware of any way to use CompiledQuery with DbContext and there also aren't any plans to make this work.

Transaction wrapped around Enterprise Data Library code + Entity Framework code

Hey I have a unique and troubling situation.
I am working on a project where my team has used a mixture of Enterprise Data Library plus Entity Framework. Obviously this probably not recommended but it is what I'm stuck with. I would like to take a method written using Enterprise Data Library and also take a different method written using Entity Framework, and wrap both of these methods in a single transaction (without requiring Microsoft Distributed Transaction Service). I'm hoping to minimize rewriting code and be able to wrap the two methods in a single transaction just as they are. Is this possible? Thanks.
Using SQL Server 2008 and .NET 4.0
I suppose you want to mix EF and EntLib queries in the same TransactionScope, without using DTC.
Good news: it's possible. If you use exactly the same connection string for EntLib DAAB and EF DbContext, it will work, depending on the versions of EF, EntLib and SQL Server.
So what you have to do is:
check you have the right versions
get the version of your connection string changed by EF and use it instead of yours.
For 1, I have checked these combinations:
SQL Server must be 2008 or older
EntLib 4.1 + EF 5 doesn't work
EntLib 5 + EF 5 works
For 2, to get the connection string changed by EF you have to debug the execution of code that uses an instance of a DbContext. Set a breakpoint and watch or inspect the DbContext Database.Connection.ConnectionString property. That's the EF version of your connection string. Use it for both EF and EntLib and you'll get rid of DTC.

Issue with AssociationSet in EF when changing target from .NET 4.0 to 3.5

I developed a Repository component targeting the .NET 4 Framework that uses EF. In my EF I use tables already existing in the Database.
In the Database I have 4 tables representing entities and 3 association tables (the relationships between the entities are all many-to-many)
However these tables at Database level do not have any relation between each other. Since I do not have rights to modify the Database, I added the relations directly in the EF. I named them, I specified the navigation properties and then I successfully compiled and tested the project.
Now I have to reference this Repository project from a Web application using the .NET 3.5. Therefore also the Repository project must reference the .NET 3.5.
I correctly copied the connection string from the Repository project to the web.config, I compiled the project and...it gives me a compile error saying that there is
"no mapping specified between EntitySet/AssociationSet"
and then lists the relationships between tables/entities.
I guess this error is given because there are no associations at Database level. How can I solve this issue without having to rewrite all my code?
You cannot use an EF 4 EDMX in EF 3.5 period. You can, however, use an EF 3.5 EDMX in EF 4, but the EF 4 designer won't understand it.
One possible fix is to make your EF 4 project an out of process server.

entity framework with SP

I'm using VS 2008 with SP1. I want to use SP in the entity framework. The problem is that my SP returns more than 1 result set. How do I get the multiple result sets? All the online examples are showing single result. Please help me.
Entity Framework unfortunately does not support multiple result sets from stored procedures - not even in the .NET 4 release.
You will need to either rewrite your stored procs, or access them using standard, bare-bones ADO.NET - and ask Microsoft for support for multiple SP result sets in EF 5 !! I'll cast my vote in favor, too!
Related to this question:
Entity Framework - get records in multiple tables using stored procedure
Another SO user reports success with a plugin project, EF Extensions.
As marc_s describes, the feature is not built in to EF... another reason for DBA Developers to shy away from EF, imho.