Upgrading EF in pregenerated views: The default target Entity Framework version requires the edmx schema version 2 or lower - entity-framework

I have pre-generated views following the templates of the next link:
http://blogs.msdn.com/b/adonet/archive/2008/06/20/how-to-use-a-t4-template-for-view-generation.aspx
I need to improve to Entity Framework 5.0 but if I replace the schemas as following:
stringBuilder.Replace("http://schemas.microsoft.com/ado/2008/09/mapping/cs", "http://schemas.microsoft.com/ado/2009/11/mapping/cs");
stringBuilder.Replace("http://schemas.microsoft.com/ado/2008/09/edm", "http://schemas.microsoft.com/ado/2009/11/edm");
stringBuilder.Replace("http://schemas.microsoft.com/ado/2008/10/edmx","http://schemas.microsoft.com/ado/2009/11/edmx");
stringBuilder.Replace("http://schemas.microsoft.com/ado/2009/02/edm/ssdl", "http://schemas.microsoft.com/ado/2009/11/edm/ssdl");
I still having the following error:
Warning 3 The default target Entity Framework version requires the
edmx schema version 2.0.0.0 or lower. The specified schema is version
3.0.0.0. To avoid this warning specify the target Entity Framework version explicitly. You can do this by using the EdmGen.exe
command-line tool with the targetVersion option, or by including the
targetEntityFrameworkVersion parameter when calling the GenerateCode
method.
Any idea of how to solve this issue using templates?
What is the equivalent of adding /targetversion:4.5 to EdmGen using templates?

I found the solution to my problem...
There was a leading help in the following link:
http://blog.3d-logic.com/2012/05/28/entity-framework-code-first-and-pre-generated-views/
moozzyk says:
August 5, 2012 at 11:51 pm
I did see this when using Visual Studio 2012 and EF5. For now the workaround is to edit the >template. Change the line 70 from:
var errors = viewGenerator.GenerateViews(mappingItemCollection, writer).ToList();
to:
var errors = viewGenerator.GenerateViews(mappingItemCollection, writer, >EntityFrameworkVersions.Version3).ToList();
Sorry for the inconvenience.
I had to slighlty modify my code in a similar way, from:
IList errors = viewGenerator.GenerateViews(mappingItems, writer);
To:
IList errors = viewGenerator.GenerateViews(mappingItems, writer, EntityFrameworkVersions.Version3);
After that, no warning nor error whatsoever.

Related

ESType error when ModelDrivenControllerBase is using to call MDrivenEcoSpaceAndModelForNetStandard

a code MyController:ModelDrivenControllerBase<EcoProject1EcoSpace> in the mvc or webapi netcore project shows a error "the type 'MDrivenTemplateProj.EcoProject1EcoSpace' cannot be used as type parameter 'ESType' in the generic type or method 'ModelDrivenControllerBase<ESType>'. There is no implicit reference conversion from 'MDrivenTemplateProj.EcoProject1EcoSpace' to 'Eco.Handles.DefaultEcospace" + annoying request to add ref to the 'MDriven.Handles.netStandard, version=7.0.0.0, culture=neutral, publickeytoken=null'. (always version 7.0.0.0!)
Could you please advise how to avoid such kind of errors?
I'm trying to develop the webapi netcore 3.1 app that has ref to MDrivenEcoSpaceAndModelForNetStandard project using the NetFramework 4.x. experience.
Seems that is it wrong way for the netcore project.
Thank you!
Brand new MDriven packages on nuget targeting .netStandard2.1 and .net5 available now.
They have correct build version numbers, and are more granular in packages than the old Eco package.
https://wiki.mdriven.net/index.php/MVC
https://www.nuget.org/packages?q=MDriven*
Old style still valid:
ref to the MDrivenEcoSpaceAndModelForNetStandard project in your netcore webapi
leave ControllerBase as a base class for your MVC controller
create and activate new ecospace in the constructor of your controller
_es = new MDrivenTemplateProj.EcoProject1EcoSpace();_es.Active = true;
you can call CreateFromViewModel method if you want to use VMs, ex.
var vmc = Eco.ViewModel.Runtime.ViewModelHelper.CreateFromViewModel("SampleViewModel", this._es, null, false);
Manual fixes that are still required in MDrivenEcoSpaceAndModelForNetStandard project:
EcoProject1EcoSpace.Designer.cs - this.persistenceMapperSharer1.MapperProviderTypeName auto generated value is incorrect
EcoProject1PMP.Designer.cs - this.EcoSpaceTypeName auto generated value is incorrect
be ready that your build in VS EcoProject modeller will not be able to start persistence after the fixes above. It will show you "No suitable constructor found" message

N-Tier-Entity-Framework: 'GeneratedTextTransformation.ProjectUtility' does not contain a definition for 'ResolveProjectPath'

When I upgraded to the newest beta (in order to get the fixes in the generator for some inheritance issues allegedly resolved per this question), I received 2 new errors at the same line in the T4 when trying to generate the classes:
Error 9 Compiling transformation:
'Microsoft.VisualStudio.TextTemplatingA3EC3BD3E5F228A9BC1C929F13763FE3AE36C19F432A59FEB1DDE5D0F681EB7C29852716DDA78FEF727C80DDC6674538B07CA98B354C4948632A3F2150F25ADA.GeneratedTextTransformation.ProjectUtility'
does not contain a definition for 'ResolveProjectPath'
and
Error 10 Compiling transformation:
'Microsoft.VisualStudio.TextTemplatingA3EC3BD3E5F228A9BC1C929F13763FE3AE36C19F432A59FEB1DDE5D0F681EB7C29852716DDA78FEF727C80DDC6674538B07CA98B354C4948632A3F2150F25ADA.GeneratedTextTransformation.T4Context'
does not contain a definition for
'GetFullPath'
The error occurs in (project path)\T4\NTierEF.NTierEntityGenerator.CS.ttinclude
Is there something in T4 that I need to fix?
Should've seen this before, but the answer is on their codeplex discussions page:
https://ntieref.codeplex.com/discussions/559965
The solution is to install the beta extension (which is not yet available on the Visual Studio gallery)

Upgrade to EF6 on .net4 - System.Data.MetadataException: Schema specified is not valid

I have an asp.net website running under .net v4.
I have upgraded from Entity Framework v5 to v6.02 and all worked fine running locally on IIS express and .net4 using the EntityFramework v4 dll provided by nuget.
I publish to my hosting company and get the error below. Upgrading to .net4.5 might help, but this is not an option on my provider at the moment.
Any suggestions?
System.Data.MetadataException: Schema specified is not valid. Errors: BkkpsModel.csdl(2,9) : warning 0005: Could not find schema information for the attribute 'Namespace'. BkkpsModel.csdl(2,32) : warning 0005: Could not find schema information for the attribute 'Alias'. BkkpsModel.csdl(2,98) : error 0005: The 'http://schemas.microsoft.com/ado/2009/02/edm/annotation:UseStrongSpatialTypes' attribute is not declared. BkkpsModel.csdl(2,2) : error 0010: The element Schema in namespace http://schemas.microsoft.com/ado/2009/11/edm was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm, http://schemas.microsoft.com/ado/2007/05/edm, http://schemas.microsoft.com/ado/2008/09/edm.
You created an EDMX file with Entity Framework 6 but you using it with Entity Framework 5.
Entity Framework 6 uses EDMX file with version 3.0 but Entity Framework 5 does not support it.
You must repair your EDMX file from version 3.0 to version 2.0
The easiest way to do that is open EDMX in Visual Studio 2012 project with Entity Framework 5 or older. The entity data model designer show error: unable to display file. The file references an XML namespace that is inconsistent with the target framework of the project. Than click the modify link and the designer automaticly repair your EDMX file.
OR:
1. open your EDMX file as XML Editor
2. change the following elements:
from:
<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx">
to:
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
from:
xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl"
to:
xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl"
from:
xmlns="http://schemas.microsoft.com/ado/2009/11/edm"
to:
xmlns="http://schemas.microsoft.com/ado/2008/09/edm"
from:
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
to:
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
... for all inconsistent xmlns
Another way of achieving what Cyrus said (downgrading from edmx v3 to ednx v2) is in the answer for another question:
EDMX .NET 4.5 to 4.0?
In my case, I rebuilt the Solution and the edmx compiled, changed a bunch of DLLs and PDBs and I was able to open the EDMX just fine. Hope that helps.
Vishwa

MEF - Migration from .NET 3.5 to .NET 4.0

I've got an easy sample from the internet that works fine in the .NET 3.5 framework using System.ComponentModel.Composition.dll version v2.0.50727
I've changed the project definition and changed the target to .NET 4.0 and it works perfect.
When I replace the v2.0.50727 version of the above .dll to the latest version which is v4.0.30319 I get an error that complains during the composition of the container. The code where it break is as follows:
private void LoadPlugins() {
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
var container = new CompositionContainer(catalog);
container.ExportsChanging += new EventHandler(container_ExportsChanging);
var batch = new CompositionBatch();
batch.AddPart(this);
container.Compose(batch); // throws Exception
}
And the exception is the following:
System.ComponentModel.Composition.ChangeRejectedException was unhandled
Message=The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) More than one export was found that matches the constraint '((exportDefinition.ContractName == "MefTutorial.IPlugin") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "MefTutorial.IPlugin".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.
Resulting in: Cannot set import 'MefTutorial.PluginConsumer._myPlugins (ContractName="MefTutorial.IPlugin")' on part 'MefTutorial.PluginConsumer'.
Element: MefTutorial.PluginConsumer._myPlugins (ContractName="MefTutorial.IPlugin") --> MefTutorial.PluginConsumer
What do I need to do to migrate to the .NET 4.0 concerning MEF?
Could it be that another project still references the .net 3.5 version? The error message says that there are two exports of type IPlugin, which I'm quite certain of means that finds both the 3.5 and 4.0 version of the dll.
Check that only the 4.0 version of MefTutorial is referenced and/or present.
OK, I found the problem. Apparently in the previous version the notation was as mentioned in my previous comment, but in the new .NET 4.0 version the syntax for import should be:
code>
[ImportMany(typeof(IPlugin))]
internal List _myPlugins { get; set; }
Notice the use of List and ImportMany instead of IList and Import.

Determine version of Entity Framework I am using?

I believe there are two versions 1 and 2? And version 2 is referred to as Entity Framework 4.0?
How can I tell what version is being used in an application?
This is in my web.config does this mean I am using version 2?
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Another way to get the EF version you are using is to open the Package Manager Console (PMC) in Visual Studio and type Get-Package at the prompt. The first line with be for EntityFramework and list the version the project has installed.
PM> Get-Package
Id Version Description/Release Notes
-- ------- -------------------------
EntityFramework 5.0.0 Entity Framework is Microsoft's recommended data access technology for new applications.
jQuery 1.7.1.1 jQuery is a new kind of JavaScript Library....
It displays much more and you may have to scroll back up to find the EF line, but this is the easiest way I know of to find out.
There are two versions: 1 and 4. EFv4 is part of .net 4.0, and EFv1 is part of .net 3.5 SP1.
Yes, the config setting above points to EFv4 / .net 4.0.
EDIT
If you open the references folder and locate system.data.entity, click the item, then check the runtime version number in the Properties explorer, you will see the sub version as well. Mine for instance shows runtime version v4.0.30319 with the Version property showing 4.0.0.0. The EntityFramework.dll can be viewed in this fashion also. Only the Version will be 4.1.0.0 and the Runtime version will be v4.0.30319 which specifies it is a .NET 4 component. Alternatively, you can open the file location as listed in the Path property and right-click the component in question, choose properties, then choose the details tab and view the product version.
can check it in packages.config file.
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.0.2" targetFramework="net40-Client" />
</packages>
if you are using EF core this command below could help
dotnet ef --version
To answer the first part of your question: Microsoft published their Entity Framework version history here.
If you open the references folder and locate system.data.entity, click the item, then check the runtime version number in the Properties explorer, you will see the sub version as well. Mine for instance shows v4.0.30319 with the Version property showing 4.0.0.0.
If you go to references, click on the Entity Framework, view properties It will tell you the version number.
internal static string GetEntityFrameworkVersion()
{
var version = "";
var assemblies = System.AppDomain.CurrentDomain.GetAssemblies().Select(x => x.FullName).ToList();
foreach(var asm in assemblies)
{
var fragments = asm.Split(new char[] { ',', '{', '}' }, StringSplitOptions.RemoveEmptyEntries).Select(x=> x.Trim()).ToList();
if(string.Compare(fragments[0], EntityFramework, true)==0)
{
var subfragments = fragments[1].Split(new char[] { '='}, StringSplitOptions.RemoveEmptyEntries);
version =subfragments[1];
break;
}
}
return version;
}
In Solution Explorer Under Project
Click on Dependencies->NuGet->Microsoft.NetCore.All-> Here list of all Microsoft .NetCore pakcages will appear. Search for Microsoft.EntityFrameworkCore(2.0.3) in bracket version can be seen
Like this
After finding package
For .NET Core, this is how I'll know the version of EntityFramework that I'm using. Let's assume that the name of my project is DemoApi, I have the following at my disposal:
I'll open the DemoApi.csproj file and take a look at the package reference, and there I'll get to see the version of EntityFramework that I'm using.
Open up Command Prompt, Powershell or Terminal as the case maybe, change the directory to DemoApi and then enter this command: 👉🏻
dotnet list DemoApi.csproj package