In my last post, I said there is a pull request by Pēteris Ņikiforovs to add support for EF-6 to Npgsql. Yesterday, I merged this pull request to the master branch of Npgsql.
With this merge, Npgsql has officially initial support for EF-6!
Another thing you will need to compile Npgsql is the latest release of EntityFramework assembly through NuGet:
PM> Install-Package EntityFramework -Pre
That's it! Now you will be able to play with Npgsql and EF-6. Check out my previous post about how to use Npgsql with EntityFramework.
I'd like to thank Pēteris Ņikiforovs for his patch. And maxbundchen for his patch about Open/Close events needed for EF-6.
Please, give it a try and let me know how it works for you.
With this merge, Npgsql has officially initial support for EF-6!
How to compile
For now, in order to compile Npgsql to use EF-6, you have to open the solution file NpgsqlEF6.sln. Later, as suggested by Pēteris Ņikiforovs, the idea is that we create a new configuration inside main project solution instead of maintain 2 separated projects.Another thing you will need to compile Npgsql is the latest release of EntityFramework assembly through NuGet:
PM> Install-Package EntityFramework -Pre
That's it! Now you will be able to play with Npgsql and EF-6. Check out my previous post about how to use Npgsql with EntityFramework.
I'd like to thank Pēteris Ņikiforovs for his patch. And maxbundchen for his patch about Open/Close events needed for EF-6.
Please, give it a try and let me know how it works for you.
Comments
Are you getting this error when you try to add the NpgsqlEF62010.csproj project to your project? If so, you should open the project separately and change its target to .net 4.0
I'll fix that in the future when I integrate the Npgsql-EF6 support into the main project file. Sorry for this inconvenience.
I hope it helps.
Should I put the "#define ENTIIES6" in the first line of every file that used "#if ENTITIES6
using System.Data.xxx
..............." etc ?
Right click your project, Properties -> Build - > Conditional compilation symbols.
I hope it helps.
The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must extend from this class and the 'Instance' member must return the Singleton instance of the provider.
And compile no problem, but when it runs and try to get data from postgre db, it occur ......'Npgsql.NpgsqlFactory......did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'.
1.GAC
cd C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools
.\gacutil -I "C:\Mono.Security.dll"
.\gacutil -I "C:\Npgsql.dll"
.\gacutil -I "C:\policy.2.0.Npgsql.dll"
.\gacutil -I "C:\EntityFramework.dll"
.\gacutil -I "C:\EntityFramework.SqlServer.dll"
cd C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bin\NETFX 4.0 Tools
.\gacutil -I "C:\Mono.Security.dll"
.\gacutil -I "C:\Npgsql.dll"
.\gacutil -I "C:\policy.2.0.Npgsql.dll"
.\gacutil -I "C:\EntityFramework.dll"
.\gacutil -I "C:\EntityFramework.SqlServer.dll"
2.Modify the machine.config
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
Add
However, the use
C:\Windows\Microsoft.NET\Framework\v4.0.30319\EdmGen.exe
To create solid, always following error:
-------------------------------------------------------------------------------
error 7001: A null was returned after calling the 'GetService' method on a store
provider instance of type 'Npgsql.NpgsqlFactory'. The store provider might not
be functioning correctly.
Generation Complete -- 1 errors, 0 warnings
-------------------------------------------------------------------------------
What should I do?
Thank you very much!
add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for PostgreSQL Server" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.91, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
That error always appears, help! %> _ <%
{
#if ENTITIES
if (true || serviceType == typeof(DbProviderServices))
return NpgsqlServices.Instance;
else
#endif
return null;
}
==========================================================================
The parameter must is 'System.Data.Entity.Core.Common.DbProviderServices'.
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql" />
</providers>
Thanks in advance.
Malcolm Jerry Leung, thank you very much, your method also solves my problem (although edmgen.exe not support EF6, but with npgsql finally able to use the windows inside EF6)
However, new problems come, my project is going to deploy the Linux + Mono 3.0.12,
But in this context the following error message, even though I used the EF6 Mono git source code to compile a npgsql (mono git above EF6 is alpha2), also reported this error
Francisco Figueiredo Jr. Will be able to publish a mono 3.0.x-based version of npgsql for EF6 do? Thank you!
The requested feature is not implemented.
StackTrace:
at System.Reflection.AssemblyName.ReferenceMatchesDefinition (System.Reflection.AssemblyName reference, System.Reflection.AssemblyName definition) [0x00000] in :0
at System.Data.Entity.Core.Metadata.Edm.DefaultAssemblyResolver.ResolveAssembly (System.Reflection.AssemblyName referenceName) [0x00000] in :0
at System.Data.Entity.Core.Metadata.Edm.DefaultAssemblyResolver.TryResolveAssemblyReference (System.Reflection.AssemblyName refernceName, System.Reflection.Assembly& assembly) [0x00000] in :0
at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource.ResolveAssemblyName (System.String assemblyName, System.Data.Entity.Core.Metadata.Edm.MetadataArtifactAssemblyResolver resolver) [0x00000] in :0
at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader (System.String path, ExtensionCheck extensionCheck, System.String validExtension, ICollection`1 uriRegistry, System.Data.Entity.Core.Metadata.Edm.MetadataArtifactAssemblyResolver resolver) [0x00000] in :0
at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader.Create (System.String path, ExtensionCheck extensionCheck, System.String validExtension, ICollection`1 uriRegistry, System.Data.Entity.Core.Metadata.Edm.MetadataArtifactAssemblyResolver resolver) [0x00000] in :0
at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader.Create (System.String path, ExtensionCheck extensionCheck, System.String validExtension, ICollection`1 uriRegistry) [0x00000] in :0
at System.Data.Entity.Core.Metadata.Edm.MetadataCache.SplitPaths (System.String paths) [0x00000] in :0
at System.Data.Entity.Core.Common.Utils.Memoizer`2+c__AnonStorey14D[System.String,System.Collections.Generic.List`1[System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader]].<>m__159 () [0x00000] in :0
at System.Data.Entity.Core.Common.Utils.Memoizer`2+Result[System.String,System.Collections.Generic.List`1[System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader]].GetValue () [0x00000] in :0
at System.Data.Entity.Core.Common.Utils.Memoizer`2[System.String,System.Collections.Generic.List`1[System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader]].Evaluate (System.String arg) [0x00000] in :0
at System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetOrCreateMetdataArtifactLoader (System.String paths) [0x00000] in :0
at System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace () [0x00000] in :0
at System.Data.Entity.Core.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection () [0x00000] in :0
at System.Data.Entity.Core.Objects.ObjectContext..ctor (System.Data.Entity.Core.EntityClient.EntityConnection connection, Boolean isConnectionConstructor, System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, System.Data.Entity.Core.Common.Internal.Materialization.Translator translator, System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory columnMapFactory, IDbCommandInterceptor commandInterceptor) [0x00000] in :0
at System.Data.Entity.Core.Objects.ObjectContext..ctor (System.Data.Entity.Core.EntityClient.EntityConnection connection) [0x00000] in :0
at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel () [0x00000] in :0
at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel () [0x00000] in :0
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext () [0x00000] in :0
at System.Data.Entity.Internal.InternalContext.Initialize () [0x00000] in :0
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType (System.Type entityType) [0x00000] in :0
at System.Data.Entity.Internal.Linq.InternalSet`1[PandaSystem.DataBase.Models.OrderManager.t_client].Initialize () [0x00000] in :0
at System.Data.Entity.Infrastructure.DbQuery`1[PandaSystem.DataBase.Models.OrderManager.t_client].System.Linq.IQueryable.get_Provider () [0x00000] in :0
at System.Linq.Queryable.FirstOrDefault[t_client] (IQueryable`1 source) [0x00000] in :0
at PandaSystem.BO.Controllers.OrderManager.ClientAcountAPIController.Login (System.String email, System.String password) [0x00000] in :0
I will create Npgsql EF6 for Mono 3.x
Do you get this "feature not implemented" error when running edmgen or when running your app in Mono 3.x?
Error "feature not implemented" in mono 3.0.12 of mvc4 (. Net 4.0) site, and edmgen has not been able to use (at present does not seem to support the ef-6).
i got null object when using it with parameter typeof(DbProviderServices).
When i decompile source of NpgsqlFactory i see "if" statement with typeof(DbProviderServices), but it didn't work.
Thanks for answer
Any chance to have support for DbFunctionCommandTree within NpgsqlServices.TranslateCommandTree?
I have to use traditional id generator. It is built as a PostgreSQL function.
The function new_seq_id:
---
CREATE OR REPLACE FUNCTION new_seq_id()
RETURNS character varying AS ...
---
The edmx summary:
---
<edmx:Edmx ...>
<edmx:Runtime>
<edmx:StorageModels>
<Schema ...>
<Function Name="new_seq_id" StoreFunctionName="new_seq_id" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="false" ParameterTypeSemantics="AllowImplicitConversion" Schema="public" />
</Schema ...>
</edmx:StorageModels>
<edmx:ConceptualModels>
<Schema ...>
<EntityContainer ...>
<FunctionImport Name="new_seq_id" ReturnType="Collection(String)"/>
</EntityContainer>
</Schema ...>
</edmx:ConceptualModels>
<edmx:Mappings>
<Mapping Space="C-S" ...>
<EntityContainerMapping ...>
<FunctionImportMapping FunctionImportName="new_seq_id" FunctionName="KanauModel.Store.new_seq_id"/>
</EntityContainerMapping>
</Mapping>
</edmx:Mappings>
</edmx:Runtime>
</edmx:Edmx>
---
The class summary:
---
public partial class KanauEntities : ObjectContext
{
public ObjectResult<global::System.String> new_seq_id()
{
return base.ExecuteFunction<global::System.String>("new_seq_id");
}
}
---
It gets ArgumentException from NpgsqlServices.TranslateCommandTree. (passing DbFunctionCommandTree)
I'll help you what I can do.
thanks
kenji uno
However we may need good edmx generator to ease code generation for StoredProcedures/Functions support.
By the way, I'm using VS 2012 Express, so I cannot try EF designer support. Even if it has good generator support.
EdmGen2 can generate edmx (ssdl,csdl,msl) for older ObjectContext support with Npgsql provider.
It also writes Functions support into ssdl.
But we need to write Functions support into msl and csdl in hand work.
Probably ssdl needs to be tweaked for Parameter type issue.
thanks
kenji uno
I love Npgsql so much. It is significantly good library :)
I've fixed some problems in msl/ssdl of Npgsql, when I'm writing my edmx generator tool.
Here is link for discussion. I've posted the link for new schema files.
https://entityframework.codeplex.com/discussions/468221
thanks
kenji uno
Please, send your patches as pull request to our github project: https://github.com/npgsql/Npgsql
I'd be glad to add your patches to our codebase.
Thank you very much for your feedback and support.
Thank you.
I'll prepare pull request for you and Npgsql asap, about 2 things: schema file correction, and experimental DbFunctionCommandTree support.
"The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' 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; "
I've added the provider long before this error occured to meand i am pretty stomped, any chance you could help me figure out what is going on if i'll send you my project? (it's a tiny tiny one)
For above I have error:
Additional information: The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlFactory, Npgsql, Version=2.1.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' 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;
Next I replace NpgsqlFactory to NpgsqlServices and I have:
Additional information: The Entity Framework provider type 'Npgsql.NpgsqlServices, Npgsql' registered in the application config file for the ADO.NET provider with invariant name 'Npgsql' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application.
What is wrong?
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider"
invariant="Npgsql"
description="Data Provider for PostgreSQL"
type="Npgsql.NpgsqlServices, Npgsql" />
</DbProviderFactories>
</system.data>
I am trying to connect PostgreSQL 9.3.2 with EF 6.0.2 using Npgsql 2.x.x.
Please suggest me the compatible versions of EF and Npgsql.dll and the working setting in web.config.
Thanks in advance
Bhupendra
Estou usando o Npgsql.2.0.14.3 com EF6.0.2 ja coum o pre instalado também.
Não estou conseguindo inserir registros com colunas que tem uma sequence (autoincremento).
Segue os codigos.
#db
CREATE TABLE tb_unidade
(
cod_unidade bigint NOT NULL DEFAULT nextval('sq_tb_unidade'::regclass),
cod_pesquisa character varying(3) NOT NULL,
descricao character varying(20) NOT NULL,
CONSTRAINT tbentries_unidade_pkey PRIMARY KEY (cod_unidade)
)..
#poco
[Table("tb_unidade", Schema = "public")]
public class UnidadeEntidade : IEntidadeBase
{
[Key]
[Column("cod_unidade")]
public Int64 Codigo { get; set; }
[Column("cod_pesquisa")]
[MaxLength(3), MinLength(1)]
public string CodPesquisa { get; set; }
[Column("descricao")]
[Required(ErrorMessage="Descrição não foi informada.")]
public string Descricao { get; set; }
}
#ef
1)
var db = OvniContext.CreateContext();
db.UnidadesContext.Add(item);
db.SaveChanges();
2)
var db = OvniContext.CreateContext();
db.Entry(item).State = System.Data.Entity.EntityState.Added;
db.SaveChanges();
em ambos os casos aparece a exception:
A null store-generated value was returned for a non-nullable member 'Codigo'.
O Erro so ocorre para inserções.
Poderia ajudar?
https://groups.google.com/forum/#!topic/npgsql-help/97X1QX5WE5k
Terei que baixar o codigo pra ver :(.
I have a question for EF6 and new Npgsql.
I used NuGet to install Npgsql & EF6. Then, I added data object and dbcontext manually. And, It's worked fine.
My question is : How can created data object and object context automatically by edmx ?
or it doesn't work ?
Thank you for answer. :)
null store-generated value was returned for a non-nullable member 'id'
Estrutura da tabela.
CREATE TABLE tab_emp
(
id serial NOT NULL,
cnpj text,
ie text,
razao text NOT NULL,
fantasia text NOT NULL,
im text,
obs text,
ativo boolean NOT NULL DEFAULT true,
CONSTRAINT prk_emp PRIMARY KEY (id),
CONSTRAINT unc_emp UNIQUE (razao, cnpj, fantasia)
)
WITH (
OIDS=FALSE
);
ALTER TABLE tab_emp
OWNER TO postgres;
-- Index: ind_emp_id
-- DROP INDEX ind_emp_id;
CREATE UNIQUE INDEX ind_emp_id
ON tab_emp
USING btree
(id);
-- Trigger: trg_emp_logs on tab_emp
-- DROP TRIGGER trg_emp_logs ON tab_emp;
CREATE TRIGGER trg_emp_logs
AFTER INSERT OR UPDATE OR DELETE
ON tab_emp
FOR EACH ROW
EXECUTE PROCEDURE trf_reglogs();
ALTER TABLE tab_emp DISABLE TRIGGER trg_emp_logs;
Possiveis causas do erro:
INSERT INTO "public"."tab_emp"("fantasia","razao","cnpj","ie","im","obs","ativo") VALUES (E'asdfasdfasdfasdfasdfasdfas',E'asdfasdfasdfasdfasdfasfasdfas',E'12.013.121/3321-32',E'32165646546546565',NULL,NULL,cast(TRUE as boolean));
SELECT currval(pg_get_serial_sequence('"public"."tab_emp"', 'id')) AS "id";
Sugestão:
INSERT INTO "public"."tab_emp"("fantasia","razao","cnpj","ie","im","obs","ativo") VALUES (E'asdfasdfasdfasdfasdfasdfas',E'asdfasdfasdfasdfasdfasfasdfas',E'12.013.121/3321-32',E'32165646546546565',NULL,NULL,cast(TRUE as boolean)) RETURN "id";
Existe uma causa especifica para o erro?
{"ERRO: 22007: sintaxe de entrada é inválida para tipo time: \"10.11:12:00\""}
INSERT INTO "public"."tab_procedim"("nome","realizado","comentario","previsaoexe","horainicial","horafinal","previsao","dataa","obrig","ativo","procedimgrupo","empsyst","empsystvers","ordem","status","colab","colab_alter","emp") VALUES (E'ASDFASDF',NULL,NULL,TIMESTAMP '2014-05-31T09:00:00.0000000',TIMESTAMP '0001-01-01T00:00:00.0000000',TIMESTAMP '0001-01-01T00:01:00.0000000',TIME '10.11:12:00',TIMESTAMP '0001-01-01T00:00:00.0000000',cast(FALSE as boolean),cast(TRUE as boolean),130,23,0,0,11,3,3,7);
SELECT currval(pg_get_serial_sequence('"public"."tab_procedim"', 'id')) AS "id"
Hi, all!
Sorry for late response.
To all who are having problems with EF, please, check this post: http://fxjr.blogspot.com.br/2014/02/using-entity-framework-6-with-npgsql-210.html
You will need to try Npgsql 2.1.x
Bruno and Leonidio, in your case, you will need to use our master branch version. Support for what you are doing will be available in 2.2.x version.
像壞人的好人, Currently support for using edmx isn't very good yet. Sorry for that. I'll create a post talking about the current situation with edmx.
Signature:
download descarga facebook gratis para Android celular and download free descargar facebook gratis and descargar facebook gratis , descarga facebook
Signature:
download free Descargar Whatsapp Para Android and download baixar whatsapp para celular online and descargar whatsapp , baixar whatsapp gratis
Signature:
The place to play all unblockedgames online. Here you can find every blocked games such as: unblocked games , unblocked games happy , unblocked games 77 ,