.net - Cannot generate C# class from PostgreSQL view using Npgsql + EF6 code first -


i trying use entity framework code first method connect postgresql database, , when use entity data model wizard in visual studio generate c# class database, can generate classes each table in database successfully, views in database cannot generated. entity data model wizard http://linearbench.com:9000/lbstest/ef.png c# class generated http://linearbench.com:9000/lbstest/code.png

can told me did wrong? use entity framework 6.1.3, npgsql 2.2.5. posgresql database version 9.3.6 installed on ubuntu server.

thanks

i know question little bit old now, ill chime in here else may looking solutions here. answer may not question looking for, however, has sufficed work around solution me.

the problem views entity framework has hard time determining primary key column them. in sql server, can use isnull() function trick ef thinking column key column, equvilant coalesce() function in postgres isn't enough ef. tried generating auto-incrementing row id column, joining other tables primary keys, etc; no luck of these.

however, has emulated functionality needed far being able query views view objects extend context class functions call database.sqlquery , return queryable

for example:

suppose view in database, "foo", columns id, bar, baz. can write own poco hold view data so

public class foo {     public int id { get; set; }     public string bar { get; set; }     public string baz { get; set; } } 

and extend context class partial class definition this

public partial class foocontext : dbcontext {     public iqueryable<foo> foo =>          this.database.sqlquery<foo>( "select * foo" ).asqueryable(); } 

and can query context same other table

context.foo.where( x => id > 100 ).tolist(); //etc,etc 

you wont able inserts or use of capabilities come standard dbset, views typically used read-only queries anyways (unless youre using special insert triggers)...

but gives base call query entire view, , doesn't hit database because left queryable, you're free call other linq extensions on such filter results want.

i migrated sql server postgres sql using npgsql lib, , fix allowed views work without having make changes programs codebase, if nothing had changed @ all, , despite fact edmx not generate view objects due lack of (discernible) primary key.

hope helps!