4

我正在使用这样的 edmgen.exe 工具:

"%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

上面的代码包括 ef 模型中的视图。我不希望包含任何视图,类似于下面的屏幕截图。如何才能做到这一点? 在此处输入图像描述

4

1 回答 1

7

看起来没有办法使用 edmgen 来做到这一点。使用反射器,我发现 edmgen 用于System.Data.Entity.Design.dll完成其工作,您可以像这样以编程方式排除数据库视图和函数:

        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);
于 2013-05-15T17:58:52.033 回答