Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude views when generating a model using edmgen.exe?

I am using the edmgen.exe tool like this:

"%windir%\Microsoft.NET\Framework\v4.0.30319\edmgen.exe" /mode:fullgeneration 
/c:"Data Source=%datasourceserver%; Initial Catalog=School; Integrated Security=SSPI" 
/project:School /entitycontainer:SchoolEntities /namespace:SchoolModel /language:CSharp

above code includes the views in the ef model. I don't want any views to be included, similar to screenshot below. How can this be done? enter image description here

like image 230
morpheus Avatar asked Mar 25 '23 00:03

morpheus


1 Answers

Looks like there is no way to do this using edmgen. Using reflector, I found that edmgen uses System.Data.Entity.Design.dll to do its work, and you can exclude the db views & functions programatically like this:

        var essg = new EntityStoreSchemaGenerator("System.Data.SqlClient", ConfigurationManager.ConnectionStrings["MST"].ConnectionString, "EFModel");
        essg.GenerateForeignKeyProperties = true;
        var filter1 = new EntityStoreSchemaFilterEntry(null, null, null, EntityStoreSchemaFilterObjectTypes.Table, EntityStoreSchemaFilterEffect.Allow);
        var filter2 = new EntityStoreSchemaFilterEntry(null, null, null, EntityStoreSchemaFilterObjectTypes.View, EntityStoreSchemaFilterEffect.Exclude);
        var filter3 = new EntityStoreSchemaFilterEntry(null, null, null, EntityStoreSchemaFilterObjectTypes.Function, EntityStoreSchemaFilterEffect.Exclude);
        var filters = new EntityStoreSchemaFilterEntry[] { filter1, filter2, filter3 };
        var errors1 = essg.GenerateStoreMetadata(filters);
like image 122
morpheus Avatar answered Apr 26 '23 16:04

morpheus