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

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...

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())
{
// ...
}

EF migrations claims there were changes in the context while there were none

I'm using Entity Framework Migrations & Code First and recently encountered a very weird problem.
The problem was reproduced with versions 4.3.1 and 4.4.
EF thinks that the context was changed while actually it didn't.
It happens when I change the path of the solution. for example:
If my solution is located in C:\integration\something.sln the migration may work but if now I will change the path to C:\development\something.sln and re-build the solution the migration will throw an exception saying there are pending changes in the database. (Of course without any changes in the source code.
I used IL Disassembler to create a dump of the output assemblies and with BeyondCompare I saw that there are differences. I assume the data is the same but its written in different order...
How EF determines if there were changes in the context? Is it possible that the assembly check-sum comes out different and will cause EF to think that there were changes?
Any ideas are most welcome...
First, this is not a migration issue - its probably a bug in the Entity Framework's algorithm to check if there are changes in the database.
I had a class hierarchy that contained an abstract class with no properties, making that class not abstract solved the problem.
After gaining some precious debugging experience, I found several ways to solve this issue and each one raised more eyebrows than the one before which makes me very convinced that I fell on a very rare corner case. As I mentioned, I decided to solve by making a class not abstract.
I tried to reproduce the bug in a clean solution so I can send it to Microsoft but until now it didn't really work.
So... to sum things up, if you find yourself with such a problem (very frustrating one), a good tip is to look for abstract classes!

System.Data.MetadataException - seems more stubborn than most people's

I have gone through this post and the links, and still can't solve my issue.
I have changed my config to name the assembly, but it makes no odds.
We recently moved the projects and think that might be an issue - but how to solve it if so. I don't quite understand how EF when running finds the cdsl etc. files I thought they were embedded in the dll [it is set to do so]?
The service having the issue doesn't directly use EF itself, it uses another DLL which DOES. I also added a direct ref to the DLL but no joy.
Also, the same code (the dll that contains the functionality, not the wrapper service) using the same connections strings works fine in my system test project via the IDE.
Turned out to be down to incorrect initialisation of StructureMap and not really to do with EF itself.

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

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.

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