EntityFramework-Reverse-POCO-Code-First-Generator icon indicating copy to clipboard operation
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard

Table Valued Function - Can't get to create

Open brillious opened this issue 6 years ago • 0 comments

Hi

I have today decided to use a table valued function in my c# code for the fiirst time. However I don't seem to be able to generate them up code generation.

Settings I have altered in my Database.tt file...

FilterSettings.IncludeTableValuedFunctions = true; // If true, for EF6 install the "EntityFramework.CodeFirstStoreFunctions" NuGet Package.

I figured if this is generating a table, then I would need to add a table filter too. All my functions begin with exfn_.

FilterSettings.TableFilters.Add(new RegexExcludeFilter(new Regex("^exfn_")));

What am I missing? Do I need to do anything else? The rest of my Database .tt file is as follows.

<#@ include file="EF.Reverse.POCO.v3.ttinclude" #>
<#
    // v3.0.5
    // Please make changes to the settings below.
    // All you have to do is save this file, and the output file(s) are generated. Compiling does not regenerate the file(s).
    // A course for the older v2 generator is available on Pluralsight at https://www.pluralsight.com/courses/code-first-entity-framework-legacy-databases

    // Settings ***************************************************************************************************************************
    // Only the most popular settings are listed below.
    // Either override Settings.* here, or edit the Settings, FilterSettings and SingleContextFilter classes located at the top of EF.Reverse.POCO.v3.ttinclude
    
    // For help on the various Types below, please read https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/Common-Settings.*Types-explained
    // The following entries are the the only required settings.
    Settings.DatabaseType            = DatabaseType.SqlServer; // SqlServer, SqlCe. Coming next: PostgreSQL, MySql, Oracle
    Settings.TemplateType            = TemplateType.EfCore3; // Ef6, EfCore2, EfCore3, FileBased. FileBased specify folder using Settings.TemplateFolder
    Settings.GeneratorType           = GeneratorType.EfCore; // Ef6, EfCore, Custom. Custom edit GeneratorCustom class to provide your own implementation
    Settings.UseMappingTables        = false; // Set to false for EfCore. EFCore will add support for this in v3. If true, mapping will be used and no mapping tables will be generated. If false, all tables will be generated.
    Settings.FileManagerType         = FileManagerType.Custom; // VisualStudio = .NET project; Custom = .NET Core project; Null = No output (testing only)
    Settings.ConnectionString        = @"*************";
    Settings.DbContextName           = "EntitiesDB";
    Settings.GenerateSeparateFiles   = false;
    Settings.Namespace               = "gMIS.Model"; // Override the default namespace here
	Settings.AddUnitTestingDbContext = false;
	Settings.UsePascalCase           = false;
    Settings.EntityClassesModifiers  = "public partial"; 

    // If GenerateSingleDbContext = false, this will generate multiple db contexts. Please read https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/Generating-multiple-database-contexts-in-a-single-go
    Settings.GenerateSingleDbContext              = true; // Set this to false to generate multiple db contexts.
    Settings.MultiContextSettingsConnectionString = ""; // Leave empty to read data from same database in ConnectionString above. If settings are in another database, specify the connection string here.

    // Elements to generate ***************************************************************************************************************
    // Add the elements that should be generated when the template is executed.
    // Multiple projects can be used that separate the different concerns.
    Settings.ElementsToGenerate = Elements.Poco | Elements.Context | Elements.Interface | Elements.PocoConfiguration | Elements.Enum;
    
    // Filtering **************************************************************************************************************************
    // Filtering can now be done via one or more Regex's and one or more functions.
    // Gone are the days of a single do-it-all regex, you can now split them up into many smaller Regex's.
    // You can have as many as you like, and mix and match them.
    // These settings are only used by the single context filter SingleContextFilter (Settings.GenerateSingleDbContext = true)
    // Please read https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/Filtering
    // For further information please visit https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/Filtering
    // For multi-context filtering (Settings.GenerateSingleDbContext = false), please read https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/Generating-multiple-database-contexts-in-a-single-go
    // Single-context filtering is done via FilterSettings and SingleContextFilter classes.
    // Override the filters here, or edit directly the FilterSettings and SingleContextFilter classes located at the top of EF.Reverse.POCO.v3.ttinclude
    FilterSettings.Reset();
    FilterSettings.AddDefaults();

    // Examples:
    FilterSettings.IncludeViews                = true;
    //FilterSettings.IncludeSynonyms             = false;
    FilterSettings.IncludeStoredProcedures     = true;
    FilterSettings.IncludeTableValuedFunctions = true; // If true, for EF6 install the "EntityFramework.CodeFirstStoreFunctions" NuGet Package.

    // TABLES
	FilterSettings.TableFilters.Add(new RegexIncludeFilter(new Regex("^ext_|^exvw_|^Authenticated_Session$|^Entity$|^Entity_Favourites$|^Entity_Organisations$|^Entity_Actions$|^Contact$|^Organisation$|^Organisation_Role$|^Authenticated_Session$|^Action$|^Action_Type$|^Project$|^Project_UDF$|^Project_Status$|^Project_Type$|^Project_Category$|^Enquiry$|^Enquiry_UDF$|^Enquiry_Type$|^Region$|^Enquiry_Status$|^Entity_Contacts$|^Workshop$|^Role_Membership$|^Variation$|^Variation_UDF$|^Variation_Status$|^Variation_Type$|^Variation_Design_Status$|^Variation_DO_Status|^EXT_OCE_Project$|^Table_ID$|^Document$|^Category$"))); 
	FilterSettings.TableFilters.Add(new RegexExcludeFilter(new Regex("^exfn_"))); 
	FilterSettings.TableFilters.Remove(new RegexExcludeFilter(new Regex("^exvw_sys"))); 

	//SPROCS
	FilterSettings.StoredProcedureFilters.Add(new RegexExcludeFilter(new Regex("Report|Admin|exsp_Blitz|exsp_LDAP|exsp_Xmas"))); 
	FilterSettings.StoredProcedureFilters.Add(new RegexIncludeFilter("^exsp_.*$"));

    // Create enumerations from database tables
    // List the enumeration tables you want read and generated for
    Settings.Enumerations = new List<EnumerationSettings>
    {
        // Example
        /*new EnumerationSettings
        {
            Name       = "DaysOfWeek",          // Enum to generate. e.g. "DaysOfWeek" would result in "public enum DaysOfWeek {...}"
            Table      = "EnumTest.DaysOfWeek", // Database table containing enum values. e.g. "DaysOfWeek"
            NameField  = "TypeName",            // Column containing the name for the enum. e.g. "TypeName"
            ValueField = "TypeId"               // Column containing the values for the enum. e.g. "TypeId"
        },
        new EnumerationSettings
        {
            Name       = "CarOptions",
            Table      = "car_options",
            NameField  = "enum_name",
            ValueField = "value"
        }*/
        // Code will be generated as:
        // public enum Name
        // {
        //     NameField = ValueField,
        //     etc
        // }
    };


    // Only the most popular settings are listed above.
    // Either override Settings.* here, or edit the Settings, FilterSettings and SingleContextFilter classes located at the top of EF.Reverse.POCO.v3.ttinclude


    FilterSettings.CheckSettings();
    var outer = (GeneratedTextTransformation) this;
    var fileManagement = new FileManagementService(outer);
    var generator = GeneratorFactory.Create(fileManagement, FileManagerFactory.GetFileManagerType());
    if (generator.InitialisationOk)
    {
        generator.ReadDatabase();
        generator.GenerateCode();
    }
    fileManagement.Process(true);#>

brillious avatar Oct 24 '19 06:10 brillious