Code Monkey home page Code Monkey logo

sjh37 / entityframework-reverse-poco-code-first-generator Goto Github PK

View Code? Open in Web Editor NEW
693.0 62.0 229.0 19.65 MB

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from

Home Page: https://www.reversepoco.co.uk/

License: Other

C# 95.35% Batchfile 0.01% TSQL 1.45% Smalltalk 0.01% Mustache 3.19%
reverse-engineering database code-generation entity-framework visual-studio

entityframework-reverse-poco-code-first-generator's Introduction

EntityFramework Reverse POCO Code First Generator

This generator creates code like an expert reverse-engineered your database and created the code for you. Perfectly.

Reverse engineers an existing database and generates Entity Framework Code First Poco classes, Configuration mappings, Enumerations, DbContext, FakeDbContext (for easy unit testing) and calling Stored procedures and table-valued functions.

Beautifully generated code first code that is fully customisable

  • Downloadable VSIX installer from the visual studio gallery.
  • Watch the v2 in-depth course at pluralsight logo I cover everything the v2 generator can do, and show you step-by-step how to reverse engineer your database properly.

Please note that this is not the Microsoft reverse generator. This generator creates code as if you reverse-engineered a database and lovingly created the code by hand. It also allows you to customise the generated code to your liking.

Give a Star! โญ

If you like or are using this project, please give it a star. Thanks!

Watch a short video clip (no audio)

Watch the video

To remove trial limitations, you will require a licence key.

Free to academics (you need a .edu, .ac or .sch email address), not free for commercial use.

Go to the ReversePOCO website for your licence key.

Upgrading v2 to v3

Please read the Upgrading documentation

What's new

Click here to see what's new in this release.

Supported databases

  • SQL Server
  • SQL Server Compact 3.5 and 4.0
  • PostgreSQL
  • Coming soon: Oracle, MySQL

Highly customisable output

This generator is designed to be customisable from the very beginning and not fixed and rigid like other generators. Play with the settings in the <database>.tt file. That's what it's there for.

If your database changes, re-save the <database>.tt file. That's it.

Click here to see a full list of features.

To install and use this project:

  • Use Nuget and install the relevant NuGet package for your database.

    • .Net Core: install-package Microsoft.EntityFrameworkCore.SqlServer
    • EF 6: install-package EntityFramework
  • Settings.ConnectionString is mandatory in v3, so you need to provide the connection string from your app.config/web.config/appsettings.json file. The generator uses this connection string to reverse-engineer your database. It no longer reads your connection strings from *.config files.

    For example:

    Settings.ConnectionString = "Data Source=(local);Initial Catalog=Northwind;Integrated Security=True;Encrypt=false;TrustServerCertificate=true";

  • The Settings.ConnectionString string you use must have at least these privileges: ddladmin, datareader and datawriter. ddladmin is required for reading the default constraints.

  • In Visual Studio, right click project and select "add - new item".

  • Select Online, and search for reverse poco.

  • Select EntityFramework Reverse POCO Generator.

  • Give the file a name, such as Database.tt and click Add.

  • Edit the Database.tt file and specify the full connection string in Settings.ConnectionString. The generater uses this to read your database schema and reverse engineer it.

  • Edit the Database.tt file and specify the connection string in Settings.ConnectionStringName which matches the ConnectionString key as specified in your appsettings.json, app.config or web.config.

  • Save the Database.tt file, which will now generate the Database.cs file. Every time you save your Database.tt file, the generator will reverse engineer your database.

  • There are many options you can use to customise the generated code. All of these settings are in the Database.tt files.

Connection strings

Settings.ConnectionString is mandatory in version 3. The generator uses it to read your database schema. The connection string is optionally placed into the OnConfiguring function:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder){{#newline}}
{{{#newline}}
    if (!optionsBuilder.IsConfigured){{#newline}}
    {{{#newline}}
        optionsBuilder.UseSqlServer(@""{{ConnectionString}}"");{{#newline}}
    }{{#newline}}
}{{#newline}}{{#newline}}

Settings.ConnectionStringName This is not used by the generator but is placed into the generated DbContext constructor via a call to Settings.DefaultConstructorArgument.

public {{DbContextName}}(){{#newline}}
{{#if HasDefaultConstructorArgument}}
    : base({{DefaultConstructorArgument}}){{#newline}}
{{/if}}

UI

A simple UI for the generator is available at GitHub, which helps you to create a regex to filter your tables.

Editing TT (T4) Files

To have full syntax highlighting and intellisense when editing TT files, I use the Resharper plugin ForTea. I can't imagine editing TT files without it.

No need to edit the EF.Reverse.POCO.v3.ttinclude file directly as this file is generated from a C# project. This repository includes the BuildTT file that creates the EF.Reverse.POCO.v3.ttinclude from the Generator C# project.

Getting a pull request accepted

Have a read of [https://github.com/blog/1943-how-to-write-the-perfect-pull-request](How to write the perfect pull request)

My requirements are simple:

  1. Always keep the changes to a minimum, so I can see exactly what's changed regarding the pull request. I.e. No whitespace tidy-up, Etc.
  2. No tabs, only spaces (4).
  3. Edit the Generator C# project. Running this project will create the EF.Reverse.POCO.v3.ttinclude file. This repository includes the BuildTT project that creates the EF.Reverse.POCO.v3.ttinclude from the Generator C# project.
  4. Don't be tempted to do a few different enhancements in one pull request. Have one pull request for one bug fix/enhancement.

Regards, Simon Hughes

entityframework-reverse-poco-code-first-generator's People

Contributors

0xced avatar andygjp avatar bdn-mca avatar bobbyangers avatar bogatykh avatar chris-eg avatar chris3773 avatar cody1024d avatar daiplusplus avatar damianreeves avatar davidsk avatar drizin avatar dyardygit avatar erikej avatar flcdrg avatar irfnkprc avatar jaxidian avatar joostkingma avatar ltippmann avatar makhin avatar markokacprzak avatar mdentremont avatar meixger avatar phofman avatar piqm avatar samartzidis avatar sjh37 avatar spreegabe avatar staff0rd avatar timsirmovics avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

entityframework-reverse-poco-code-first-generator's Issues

System.Linq.IQueryable

When IncludeTableValuedFunctions is set to true, tvf's are generated with IQueryable return values.

Unlike the other members of the context which are generated with full namespaces, IQueryable is generated with no namespace and causes a compiler error as the System.Linq namespace needs to be imported.

I know that additional namespaces can be manually added in the config, but can the IQueryable be generated like all other items with the fully qualified name?

Many-to-many does not use proper naming

It appears that in a many to many relationship, the first navigational property should be the plural without the foreign key and without "1" appended but in version 2.19 this does not happen.

For instance, we have the following tables:
Roles (RoleId)
Permission (PermissionId)
RolePermission (RoleId, PermissionId)

In the generated Role class, instead of a "Permissions" property in the reverse navigation , we get a property for "Permissions_PermissionId" and another for "Permissions1".

Similarly, in the generated Permission class we get properties "Roles_RoleId" and "Roles1".

It seems like the intention was to have a result where the Role class would have a property named "Permissions" and a second one named either "Permissions1" or "Permissions_PermissionId" - which would be fine if that was the result.

It appears that the error is in the POCO.Core.ttinclude with the conditional:

if (!ReverseNavigationUniquePropNameClashes.Contains(tableNameHumanCase) &&
    !ReverseNavigationUniquePropName.Contains(tableNameHumanCase))
{
    ReverseNavigationUniquePropName.Add(tableNameHumanCase);
    return tableNameHumanCase;
}

Which sees the name clash so the normal and probably intended naming doesn't happen on the first instance.

Enhanced use of comments

Instead of this:

    public System.Guid RidKey { get; set; } // RIDKey (Primary key)

Is it possible to generate this: ???

    /// <summary>
    /// RIDKey (Primary key)
    /// </summary>
    public System.Guid RidKey { get; set; }

Justification: Added value for consumers of generated DbContext, allowing them to easily identify for example primary and foreign keys via Intellisense:

efpoco2

Sample CustomPluralizationEntry's enabled by default

When adding a new Reverse Poco tt file, the Pluralization section contains entries for LiveQuizzes, Course, CustomerStatus and EmployeeStatus which were used as samples in your pluralsight course.

I think you may have left these uncommented unintentionally as all other examples are commented out.

Running transformation: System.InvalidCastException: Unable to cast transparent proxy to type 'System.IServiceProvider'.

Hi

I asked my question in stackoverflow more than 2 months ago but no one can not help me. Link

I want to run your T4 without Visual Studio so I downloaded simple-t4-engine for this purpose Simple T4 Engine Site

*** using Simple T4 Engine library is not important I can use any CustomTemplateHost if works ! ***

I wrote some code like this :

Engine engine = new Engine();
        TemplatingHost host = new TemplatingHost(System.Text.Encoding.UTF32);
        host.IncludeFileSearchPaths.Add(@"D:\IncludeFiles");

        string templateFileName = "some template";
        // NOTE: Doesn't actually seem to care about the name of the template file?  True, but does use the path to search for stuff.
        host.TemplateFile = templateFileName;
        string input = File.ReadAllText(@"D:\IncludeFiles\T4Files\Database.tt");
        string output = engine.ProcessTemplate(input, host);
        File.WriteAllText(@"D:\IncludeFiles\T4Files\Output.txt", output);

        StringBuilder sb = new StringBuilder();
        foreach (CompilerError error in host.Errors)
        {
           sb.AppendLine(error.ToString());
        }

        File.WriteAllText(@"D:\IncludeFiles\T4Files\ErrorLog.txt", sb.ToString());

But I got some errors (Output.txt is Empty)

ErrorLog.txt :

error : Running transformation: System.InvalidCastException: Unable to cast transparent proxy to type 'System.IServiceProvider'.
   at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.GetDTE()
   at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.GetCurrentProject()
   at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.GetConfigPaths()
   at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.GetConnectionString(String& connectionStringName, String& providerName, String& configFilePath)
   at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.InitConnectionString()
   at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.GetDbProviderFactory()
   at Microsoft.VisualStudio.TextTemplating31A64EBEAB614B57E81A1789EC7637709A091834D5CA991E8A2195B15E2A0DFF588B0C98DCEDA8AD6902329A28B09556BDE2A9BEDFA48812CCC12CA1E68AA1C9.GeneratedTextTransformation.TransformText()

D:\IncludeFiles contain these files :
EF.Reverse.POCO.Core.ttinclude
EF.Reverse.POCO.ttinclude
EF6.Utility.CS.ttinclude

Another try with CMD

I use CMD and TextTransform.exe with this Command :

TextTransform.exe -I "C:\IncludeFiles" Database1.tt

but shows error :

Database1.tt(0,0) : error : Running transformation: System.InvalidCastException: Unable to cast object of type 'Microsoft.VisualStudio.TextTemplating.CommandLine.CommandLineHost' to type 'System.IServiceProvider'.
   at Microsoft.VisualStudio.TextTemplatingbd94e8ea88344f96903a612633001eb5.GeneratedTextTransformation.GetDTE()
   at Microsoft.VisualStudio.TextTemplatingbd94e8ea88344f96903a612633001eb5.GeneratedTextTransformation.GetCurrentProject()
   at Microsoft.VisualStudio.TextTemplatingbd94e8ea88344f96903a612633001eb5.GeneratedTextTransformation.GetConfigPaths()
   at Microsoft.VisualStudio.TextTemplatingbd94e8ea88344f96903a612633001eb5.GeneratedTextTransformation.GetConnectionString(String& connectionStringName, String& providerName, String& configFilePath)
   at Microsoft.VisualStudio.TextTemplatingbd94e8ea88344f96903a612633001eb5.GeneratedTextTransformation.InitConnectionString()
   at Microsoft.VisualStudio.TextTemplatingbd94e8ea88344f96903a612633001eb5.GeneratedTextTransformation.GetDbProviderFactory()
   at Microsoft.VisualStudio.TextTemplatingbd94e8ea88344f96903a612633001eb5.GeneratedTextTransformation.TransformText()

I use these two way for other T4 Templates and works and show the result
Can you guide me Why your T4 can not execute in outside of VS with these ways and help me for fixing problem ?

The answer is so important for me. please help me.
Thanks.

Callback function to determine whether to include object

It would be useful to have a callback function that accepts the Schema Name and Table Name for tables / views, and returns a bool indicating whether the object is to be included. This would be an alternative to the Regex exclusions/inclusions.

I have situations with Legacy databases where for example:
Schema One has 15 objects, we want to include them all.
Schema Two has 400 objects, we only want 1.

In this case I can't filter by Schema, so I need to add in all 16 objects to the inclusion filters.

We could use 2 seperate contexts, however this duplicates the number of contexts and we can't perform queries including both contexts.

If this was to be implemented it would be good to have the same functionality for Tables, Views and Stored Procedures / TVF's, either the same callback with an object type parameter, or seperate callbacks.

Naming issues

Currently working on these -- will add more pull requests

  • Given the view inv_ItemProfit and the stored procedure inv_ItemProfits the generated property names conflict -- there's duplicate checking but I think it happens pre-pluralization.
  • Table names aren't properly scrubbed -- a '-' in a table name flows through to generated classes and properties

One to one relationship with foreign key is unique key/unique index

Hi,
Can you make the generator generate one-to-one navigation property with foreign key is unique key/unique index?
Example: I have two tables
Table 1: Id (PK), Name
Table 2: Id (PK), Name, Table1Id (FK - Unique Key)
For now, when i generate POCO, the generator generate one-to-many relationship but actually that is one-to-one relationship.
Thanks!

v2.19.3 issue with many to many generation

I have the following tables

Users (UserId, Name)
UserRoles (UserRoleId, UserId, RoleId)

when using the latest generator i am getting the following in the UserRoleConfiguration.cs file (notice the duplicated c.UserId)

HasRequired(a => a.User).WithMany(b => b.UserRoles).HasForeignKey(c => new { c.UserId, c.UserId }).WillCascadeOnDelete();

Similarly i have
Roles (RoleId, Name)
RolePermissions (RolePermissionId, RoleId, PermissionId)

in the generated RolePermissionConfiguration.cs i see duplicated c.RoleId

// Foreign keys
HasRequired(a => a.Role).WithMany(b => b.RolePermissions).HasForeignKey(c => new { c.RoleId, c.RoleId }).WillCascadeOnDelete(); // FK_RolePermissions_Roles

Column Level Attributes instead of Table

Can you create another way to add attributes but at the "Column" level, currently its setup for a table object.

I'm trying to rename columns from

Id to just "Id" and I need an attribute called [Column("TableId")] but would also be useful to but in required if not null, or max lengths etc.

Warning when building a project

We're getting this warning:

'ISiriusSqlContext.SaveChanges()' hides inherited member 'IContext.SaveChanges()'. Use the new keyword if hiding was intended.


We defined

DbContextInterfaceBaseClasses = "IContext"; // Specify what the base classes are for your database context interface

and that interface has

public interface IContext : IDisposable
{
IDbSet Set() where T : class;
int SaveChanges();
and other methods
}

What needs to be changed to avoid the warning?

Objects are getting an appended 1

I have a database with many tables in different schemas.
I have 2 tables named workflow in 2 different schemas.

The generated code while using SchemaFilterInclude = new Regex("sre");; (not specifically naming the tables) I get objects that are Workflow1 instead of Workflow.

I also tried specifying specific schema and while naming the table via TableFilterInclude - the resultant code still creates the object as Workflow1 insead of Workflow

Support Async Stored Procedure Calls

The stored procedure call generation code that exists is fantastic. Unfortunately I can't really use it because it is synchronous and the rest of our Web API code is async. It would be great if for a given stored procedure Foo, it would also generate a FooAsync() method that returns Task.

Fake DbContext doesn't inherit from DbContext like 'real' one does

One of my unit tests is failing due to the following exception;

System.InvalidCastException: Unable to cast object of type 'MyWebAPI.Data.FakeMyWebApiDbContext' to type 'System.Data.Entity.DbContext'..

Which lead me to notice that the Fake doesn't inherit from DbContext like the real one does. e.g.

[System.CodeDom.Compiler.GeneratedCodeAttribute("EF.Reverse.POCO.Generator", "2.19.1.0")]
public class MyWebApiDbContext : System.Data.Entity.DbContext, IMyWebApiDbContext

[System.CodeDom.Compiler.GeneratedCodeAttribute("EF.Reverse.POCO.Generator", "2.19.1.0")]
public class FakeMyWebApiDbContext : IMyWebApiDbContext

possible missing schema in SP

I had a stored procedure in a non-default schema, and it was written without the schema prefixed in the EXEC statement. I had to add "<#= sp.Schema>." to line 257 in the EF.Reverse.POCO.ttinclude to get it to import correctly.

Thanks.

Using statements

Where in the tt files do the using statements get inserted? i.e. using System.Data.Entity or using System.Linq ?

thx

Reverse poco generation ignores some tables

So I have isolated what I think is a bug.

Using these tables, the template will generate code for the table named CEWD_EIF_Test, but ignore all the others.

I have included the sql server script to create the database and tables, there is no data in any of them, and no indexes. I have also included my app.config and TheMissing.tt. This should allow for easy replication.

I am using SqlServer 2008r2 64bit, and Visual Studio 2013.

image

missingdbtest.zip

Create enum from table

We already have the ability to map columns to an enum type.
It would also be nice to create enums from tables.

TableValueFunction entries are not generated

This relates to v2.19.0. The parameter is set to true in the .tt file and the EntityFramework.CodeFirstStoreFunctions package is installed but there are no tvf methods in my context

Poco Naming Issue

First, great work on this. Totally love the flexibility and output of the tool. One small issue:

I am working with a legacy database that has it's table names pluralized. When the generator creates entities for tables with names that end in 'ies' it capitalizes the second-last letter of the word, which it should not.

Example:
Currencies (table) -- becomes --> CurrenCy.cs

pocogeneratorissue

I have been trying to debug the template myself to propose a fix, but debugging t4 templates has proved more complex than I have time for at the moment (when my second vs2015 instance launches to debug, it cannot find the pdb file of the t4 template and adding the debug attribute to the t4 template causes an error in the template itself).

Enable switch to force generation of Many to Many entities

I would be nice to make this code change an option:

      public void IdentifyMappingTables(List<ForeignKey> fkList, bool useCamelCase, string collectionType, bool checkForFkNameClashes, bool includeComments, bool isSqlCE)
        {
            foreach(var tbl in this.Where(x => x.HasForeignKey))
            {
                //tbl.IdentifyMappingTable(fkList, this, useCamelCase, collectionType, checkForFkNameClashes, includeComments, isSqlCE);
            }
        }

Use case: I use the generated EF model for table synchronization between server and client database, so I need a object per table...

":" in the field name

in my stored procedures there are some chars like ":" which generator does not replace it and project does not build

public partial class SpXmlFeedForFacebookReturnModel
{
public System.Int32 id { get; set; }
public System.Int32 modelid { get; set; }
public System.String title { get; set; }
public System.String description { get; set; }
public System.String g:condition { get; set; }
public System.String g:price { get; set; }
public System.String g:sale_price { get; set; }
public System.String g:product_type { get; set; }
public System.String link { get; set; }
public System.String g:image_link { get; set; }
public System.String g:availability { get; set; }
public System.String g:brand { get; set; }
public System.String g:color { get; set; }
public System.String g:size { get; set; }
public System.String g:mpn { get; set; }
public System.String g:gender { get; set; }
public System.String g:google_product_category { get; set; }
public System.String g:adwords_grouping { get; set; }
public System.String g:custom_label_0 { get; set; }
public System.Int64? rn { get; set; }
}

some stored procedures are not generated

I am using version 2.14.3 and SQL2014. When I save the .tt file, only some stored procedures are generated even I used the following regex.
StoredProcedureFilterExclude = null;
StoredProcedureFilterInclude = new Regex("usp_.*");

The following sp are generated
App.usp_CCNT_PatientLetterUpdate
App.usp_ChoiceLetterUpdate
App.usp_ColonoscopyRegReminderUpdate
App.usp_ColonoscopyRegReminderUpdate_r2

There are a lot more store procedures are not generated. For example,
App.usp_CMTUserFSRUpdate
App.usp_setUserPreference

I wonder if there something specific in the body of the sp causes the generator to ignore these sp.

Thanks.

Timestamp Column / RowVersion Column

There is an issue using generator with SqlServer Compact 4.0 and RowVersion Column
With SQL Server Standard Timestamp column type is "TimeStamp" ad is mapped to "byte[]", on SQLCompact 4.0 the type is "RowVersion" and the column is mapped to "string"

To solve the problem, i've changed the following statements on EF.Reverse.POCO.Core.ttinclude file:
col.IsRowVersion = col.IsStoreGenerated && !col.IsNullable && ( typename == "timestamp" );

to

col.IsRowVersion = col.IsStoreGenerated && !col.IsNullable && ( typename == "timestamp" || typename == "rowversion" );

and added;

case "rowversion":
                    sysType = "RowVersion";
                    break;

and added:
case "rowversion":
sysType = "byte[]";
break;

Support for EF Core

Hi, is there any plan to support EF7? EF7 is more stable now and we love EFReversePoco, so it'd be so nice to start playing with both together. Thanks!!

CodeGeneratedAttribute is missing from the generated configuration classes

Hi,

I automatically add any hand crafted configuration (any configuration without the CodeGeneratedAttribute) when I initialise my context, but to make this work I have to manually edit the EF.Reverse.POCO.ttinclude file every time I upgrade. Please can this be added to the EF.Reverse.POCO.ttinclude for consistence, as the POCOs have this attribute, and because I always forget to edit the file ๐Ÿ˜›.

Cheers,
Andy

Add index annotations

For example

Property(x => x.ContainerId)
  .HasColumnName("ContainerId")
  .IsRequired()
  .HasColumnType("uniqueidentifier")
  .HasColumnAnnotation(IndexAnnotation.AnnotationName, 
    new IndexAnnotation(new IndexAttribute("UQ_ContainerId_FieldDefinitionId", 1)
    { IsUnique = true }));

Enum generation error?

Hi Simon,

I have a public enum defined like this:

public enum CatCode { [Description("Assembly")] Assemblies = 0, [Description("Part")] Parts = 1, [Description("Electrical")] Electricals = 2, [Description("Fittings")] Fixings = 3 };

In the template, I'm trying to add the enum to a column "CategoryCode":

EnumDefinitions.Add(new EnumDefinition {Schema = "dbo", Table = "Stock", Column = "CategoryCode", EnumType = "CatCode" });

But I'm getting this error message:
Compiling transformation: The name 'EnumDefinitions' does not exist in the current context c:\Projects\Visual Studio 2013\MyDatabase.tt

Am I missing something in the template, or heaven forbid, something is wrong with the template itself?

Merge duplicate multiple result sets

If a stored procedure contains conditional statements, such as this:

IF(@someVar < @otherVar) BEGIN
   SELECT a,b,c WHERE blah
ELSE
   SELECT a,b,c WHERE blah OR blah
END

The result sets will be the same, even though two can be returned.
Instead of including ResultSet1 and ResultSet2, these can be merged and instead use a single return model.

How to overwrite an computed Guid PRIMARY KEY to Identity

I Create an table like this,

CREATE TABLE Token (
Token uniqueidentifier NOT NULL DEFAULT (newsequentialid()) ROWGUIDCOL,
Enabled bit NOT NULL 
)
ALTER TABLE Token ADD PRIMARY KEY (Token)

And get some code like that.

public UserTokenConfiguration(string schema)
{
    ToTable(schema + ".Token");
    HasKey(x => x.Token);

    Property(x => x.Token).HasColumnName("Token").IsRequired().HasColumnType("uniqueidentifier").HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Computed);
    Property(x => x.Enabled).HasColumnName("Enabled").IsRequired().HasColumnType("bit");
}

I get an Exception System.Data.Entity.Core.UpdateException ---> System.NotSupportedException,
and can't update any row in the table for that it has an Computed PRIMARY KEY. I know that I won't modify the column, and want to change it to Identity.

Is there any way for me to manually modify it to DatabaseGeneratedOption.Identity.
Or generally, is it OK to auto modify all Computed PK to Identity, for that Computed PK is NOT supported to modify, and modify is the only difference between them.

sys.extended_properties

I need to be able to create a POCO class that maps to sys.extended_properties. Can the generator currently support this?

GenerateSeparateFiles=true generates empty context class.

When setting GenerateSeparateFiles to true in order to generate one class per file, the main context class generated will be empty.

Setting GenerateSeparateFiles to false makes it work right, but all the classes are merged into one file.

TableFilterInclude applied against original and renamed table name

I am using the TableFilterInclude to control which tables/views are generated.

I found that for objects that are renamed, I have to include two entries in the Regex - one for the original name and one for the renamed version. This is not made clear in the comments (I had to debug the tt to work it out), and means I have to double up the entries in my Regex to account for both names:

TableFilterInclude = new Regex("PurchaseOrder.*|Purchase Order.*|WebOrder.*|Web Order.*|vwClientSupplier|Vw Client Supplier|vwOrders|Vw Orders");

Is this the intended behaviour?
I understand for exclusions it makes sense to apply it to both names to give the user the option of using either, but for inclusions it introduces extra work to account for both combinations.
Could you provide an option to only apply filters to either the original, or renamed names?

Add ability to specify additional mapping tables

If the UseMapping property had been set to true originally and we'd like to add an extra column to the original mapping table therefore making it non-mapping, the newly generated models are now different from the models generated originally and cause issues if the code has been already created using original models. A new property, say, AdditionalMappingTables RegEx, will help to eliminate complex workarounds.

ObjectParameter null string values

Object Parameters are generated for functions using the (string name, object value) constructor:

var exampleParam = new System.Data.Entity.Core.Objects.ObjectParameter("ExampleParam", exampleParamValue);

When an optional string parameter is null, this throws an exception in the constructor of ObjectParameter even though it is legal and neccesary to have a null value for this parameter.

This StackOverflow answer suggests using the alternative constructor, and setting the Value parameter after construction:

var exampleParam = new System.Data.Entity.Core.Objects.ObjectParameter("ExampleParam", typeof(string)) { Value = exampleParamValue }

Could this be incorporated into the generator?

Generate Invalid Return Models

Currently the following is being generated:

public System.Decimal? 01To30Days { get; set; }
public System.Decimal? 31To60Days { get; set; }
public System.Decimal? 61To90Days { get; set; }
public System.Decimal? 91To120Days { get; set; }
public System.Decimal? 120PlusDays { get; set; }

Would also be nice to have a update column function for the return models

Use #Region

Would be nice to have all of the stored proc in one region, all of the POCOs in an other, etc.

Integer suffix added incorrectly

I have a table named t_Function. The "t_" prefix is removed using the TableRename function but when the code is generated, the file and class are both named Function1.

At first I thought function was a reserved word but that doesn't seem to be the case.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.