Entity Framework 4.1, can't find Load() method? - entity-framework

Ok, I'm about to smash my keyboard with a hammer over this. I decided to play with EF this weekend and I started a project in 4.0. I find out 4.1 is out so I download and install the package.
Imagine my surprise when I go to use the Load() method in the dbExtensions and it can't find it. So I add a reference to the EntityFramework binary that the installer created, remove the System.Data.Entity reference from the project, rebuild, and it says
"The type
'System.Data.Objects.ObjectContext' is
defined in an assembly that is not
referenced. You must add a reference
to assembly 'System.Data.Entity,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'."
I tried to regenerate my model, I tried removing things, I tried directly referencing the 4.1 via usings. Nothing works.
I'm obviously missing something basic. How in the heck do I tell visual studio to use the 4.1 framework??!!

I managed to find the missing .Load() function by adding the following:
using System.Data.Entity;

Entity Framework 4.1 is not separate version. It still needs Entity Framework 4.0 and its assembly so yu can't remove System.Data.Entity.dll from your references. Also EFv4.1 is mainly about new DbContext API so unless you are going to swith from Entity objects to POCOs and DbContext you will not get any advantage by referencing EntityFramework.dll (except strongly typed Include on IQueryable).

Add a Reference to System.Data.Entity.dll from either:
GAC (.Net tab in add reference dialog)
or
C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.Entity.dll

I got the same issue, and still don't know the root cause.
Finally I use some alternative solution:
var query = from d ...
query.Load();
or
(DbSet)context.myentity).Load();
Please try.

Ladislav's post is accurate. To add a little more detail, this ADO.Net team blog post explains how to correctly replace the code generation in an EF 4.0 project with EF 4.1.
However, I have a similar issue after upgrading to 4.1 and using DbContext (including some other features) I don't have a .Load() method either. I think you were in the same place I am before you started (unnecessarily) messing with references.
Check out the link above, let me know if it helps, and if you find a solution for the missing .Load() function be sure and let us know.

Related

Can not resolve Symbol "ForSqliteHasDefaultValueSql"

I want to define a Timestamp in my EF Core Project with SQLite and wanted to use this function:
Click
I know that this function seems to be in the classic EF and maybe it is not available anymore but 3 days ago I found the right package and the extension method that I was searching. Unfortunatelly I had another problem with the code and reverted everything and now I do not find the right package anymore. It was during a hackathon during the last hours, so i really do not remember how I got it to work :/
Does anybody know which nuget package has this method? The only thing that I am referencing is Microsoft.EntityFrameworkCore.Sqlite. I allready tried the .Core and the classic EF dependencies and some random third party sqlite/ef packages, but I still can not compile this extension method :(
As you can see from the link, this method applies to EF Core versions 1.0 and 1.1.
Starting from v2.0, most of the provider specific ForAbcXyz methods have been replaced with the generic Xyz methods.
So the method you are looking for is HasDefaultValueSql. If you support multiple databases, use it inside a block enclosed with
if (Database.IsSqlite())
{
// ...
}

.NET Standard 2.0 / EntityFrameworkCore / DB2 / IBM.EntityFrameworkCore issue

Does anyone here has experience with IBM.EntityFrameworkCore package? I've created a .NET Standard 2.0 library project in VS2017, added mentioned package, and tried to make it work by following this and this tutorial from IBM website, with no luck. I get the project compiled, but at the runtime I'm getting a System.TypeLoadException with the following message:
Method 'ApplyServices' in type 'IBM.EntityFrameworkCore.Infrastructure.Internal.Db2OptionsExtension' from assembly 'IBM.EntityFrameworkCore, Version=1.1.1.101, Culture=neutral, PublicKeyToken=7c307b91aa13d208' does not have an implementation.
Any help will be appreciated!
Thanks!
Update: The exception happens as soon as I try to use the context. It means after the context is successfully created, but before DbContext.OnConfiguring call happens.
I've solved it. It turned out that this exception happens if actual entity types (i.e. MyType) aren't defined in the same assembly (project) as the context. In my solution I had entity types defined in one project, and DbContextdefined in a different project, that references the first one, of course.
The reason for me to have such design was in the fact that there are two different packages (depending on the actual OS): IBM.EntityFrameworkCore and IBM.EntityFrameworkCore-lnx. So I've created two different projects, each referencing one of these packages. Still, I wanted to have all the entity types defined once... But obviously it cannot work like that.
Update: Sadly, it turned out that this isn't the only issue. I've ran into another one, described here. Thumbs down for DB2 .NET team! It's always frustrating to work with...

Updated to EF 4.2. Then what?

Ok, so I installed EF 4.2 from NuGet. Just did Install-Package EntityFramework. That's all I've done.
Now what?
How do I know I'm using the new Framework and not the old one.
I have an existing project previously with EF 4.0. I'm also using precompiled views and custom text templates. Everything looks exactly the same after I did the update.
There will be no change in existing project. EFv4.2 contains code first mapping approach and DbContext API - neither of those affects existing EFv4.0 projection. It also contains few minor helpers like strongly typed Include but you must use them in your code. That is not something that will magically change existing code.

Configure the spark view engine!

I'm looking at launching a new site using the Spark View Engine, I am however having difficulty finding some referance to the set-up of Spark Using VS2010 and MVC2. Can anyone provide a referance to a guide that describes this process?
I've looked at some of the code in the sample but the projects dont convert to VS2010. Before I tear these apart I wonder if there is somthing already out there? I also need to configure Re-Sharper and VS to work with Spark
I have seen - http://sparkviewengine.com/documentation/configuring#AddingtoAspNetMVC
But this it's a pretty basic overview I'm looking for a real world example.
===== Edit
The source provided on DotNetSlackers doesnt run!
Errors with the mismatch of .Net version
"Dynamic view compilation failed.
(0,0): error CS1703: An assembly with
the same identity 'mscorlib,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' has
already been imported. Try removing
one of the duplicate references."
If I add the latest DLL's to the DotNetSlackers example I get the following
"Attempted to access an element as a type incompatible with the array."
protected void Application_Start()
{
SparkViewFactory svf = new SparkViewFactory();
PrecompileViews(svf);
**ViewEngines.Engines.Add(svf);**
RegisterRoutes(RouteTable.Routes);
}
On the stared line above.
Your "dynamic view compilation failed" error is because Spark hasn't yet been rebuilt to work with .NET 4.0. Your options at this point are:
1) Target .NET 3.5 instead
2) Wait for a new version of Spark
3) Get the Spark source code and rebuild it yourself against .NET 4.0 - see http://groups.google.com/group/spark-dev/msg/028d0cf129c4b1ff for further info
hmm, there are a whole bunch of introductory screencasts on the website:
http://www.sparkviewengine.com
as well as the reference documentation, which is very helpful:
http://www.sparkviewengine.com/documentation/configuring
are you having a specific problem?
I recently did a screen-cast here. Setting up on MVC2 is in the video at 6min40sec if you want to see how it's done.
http://blog.robertgreyling.com/2010/08/elegant-mvc-with-spark-way-views-were.html
As a side note - The source code has now been moved to VS2010 in the master branch and it will also compile views dynamically to .NET 4.0. avoiding the error you got. You can either download the source and recompile the latest binaries, or for your convenience, we added them to NuPack/NuGet if you'd prefer to reference them that way.
Hope that helps

EntityFramework gives IDisposable error

I use EF for the back-end DataLayer in my asp.net websites. I create a class library and add the Model in it, reference it and use it from the ASP.NET Website. But this time, I generated the model from database but it seems does not implement IDisposable, and the methods I used to see are not there. DeleteObject , SaveChanges etc. There are only Two tables in the DB and the Model was generated with only the TableSets and two methods AddToTableSet ... Had anybody encountered such a problem?
alt text http://techlipse.net/EF-problem.jpg
Did you extend the generated ObjectContext and then perhaps rename it in the EDMX? You might be looking at your part of the partial class here without the generated part.
What does the Properties panel say for your EDMX for "Entity Container Name"?
When you right click on Entities and go to definition do you get to the correct generated class?
And lastly, but probably most likely, did you perhaps delete the Reference to System.Data.Entity from the project or not reference it in your web project?
Is you web project even a Web Application project???
I have my Entity Framework code in its own project, and was referencing it from a separate project. NuGet sets EntityFramework only on the EF project, which is how the reference gets automatically configured to the latest version. To fix this error:
Tools -> Library Package Manager -> Manage Nuget Packages for Solution
Select Installed Packages and find Entity Framework
Click the Manage Button, and check all the project that will be accessing the EF Data Model.