Code Monkey home page Code Monkey logo

dto-generator's People

Contributors

gwenou avatar ivancesar-tt avatar yohney 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dto-generator's Issues

basic usage example

Sorry if i am missing something really simple, but i am not understanding exactly how to use the created class. I have a EF phone object, and I have used the generator to create a PhoneDTO object (and the associated mapper class). How do i then create a PhoneDTO object from the original Phone EF object?

Some examples code would be great!! Thanks in advance.

EntityParser.FromSyntaxTree broken in VS2017

We use dto-generator to generate dto's for entities generated using EF Core 2 database-first using the Scaffold-DbContext operation [https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db]

Target entity:

using System;
using System.Collections.Generic;

namespace COMPANY.Core.SafetyDb.Model
{
    public partial class ApplicatieObject
    {
        public int ApplicatieObjectId { get; set; }
        public int? ParentId { get; set; }
        public int ApplicatieId { get; set; }
        public int ApplicatieObjectTypeId { get; set; }
        public string ApoNaam { get; set; }
        public string ApoOmschrijving { get; set; }
        public string ApoIcon { get; set; }
        public string ApoUrl { get; set; }
        public byte? ApoIsActief { get; set; }
        public string ResourceId { get; set; }
        public long? Editstamp { get; set; }
        public string Modifiedby { get; set; }
        public string Recstat { get; set; }

        public Applicatie Applicatie { get; set; }
    }
}

Exception message:

Source code to parse must contain exactly one class declaration!

Callstack:

   at DtoGenerator.Logic.Infrastructure.EntityParser.FromSyntaxTree(SyntaxTree syntaxTree)
   at DtoGenerator.Logic.Infrastructure.EntityParser.<FromDocument>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at DtoGenerator.Logic.UI.EntityViewModel.<CreateRecursive>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at DtoGenerator.Logic.UI.EntityViewModel.<CreateRecursive>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at DtoGenerator.Logic.UI.PropertySelectorViewModel.<Create>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at DtoGenerator.Vsix.GenerateDtoCommand.<MenuItemCallback>d__13.MoveNext() in F:\git\dto-generator\src\DtoGenerator\DtoGenerator.Vsix\GenerateDtoCommand.cs:line 235
----------------------------

Interestingly, generation does succeed when i remove the navigation properties from the entity.
E.g. the following modified entity does result in generation of ApplicatieObjectDto:

using System;
using System.Collections.Generic;

namespace COMPANY.Core.SafetyDb.Model
{
    public partial class ApplicatieObject
    {
        public int ApplicatieObjectId { get; set; }
        public int? ParentId { get; set; }
        public int ApplicatieId { get; set; }
        public int ApplicatieObjectTypeId { get; set; }
        public string ApoNaam { get; set; }
        public string ApoOmschrijving { get; set; }
        public string ApoIcon { get; set; }
        public string ApoUrl { get; set; }
        public byte? ApoIsActief { get; set; }
        public string ResourceId { get; set; }
        public long? Editstamp { get; set; }
        public string Modifiedby { get; set; }
        public string Recstat { get; set; }
    }
}

Environment:

  • Visual studio Enterprise 2017 15.3.5
  • Windows 10 enterprise 1703 x64

Would love to see this fixed, thanx for your great work!

Error trying to generate dto from EF class in VS 2017

Object reference not set to an instance of an object.

at Microsoft.CodeAnalysis.SolutionParser.<>c__DisplayClass1_0.b__2(Document p)
at System.Linq.Enumerable.<>c__DisplayClass6_01.<CombinePredicates>b__0(TSource x) at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Microsoft.CodeAnalysis.SolutionParser.GetDocumentByLocation(Solution solution, SolutionLocation location, String documentName)
at DtoGenerator.Vsix.GenerateDtoCommand.d__13.MoveNext() in F:\git\dto-generator\src\DtoGenerator\DtoGenerator.Vsix\GenerateDtoCommand.cs:line 220

Below is EF class we're trying to generate DTO for:

namespace WebAPI.Data
{
using System;
using System.Collections.Generic;

public partial class invoice
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public invoice()
    {
        this.invoice_transaction = new HashSet<invoice_transaction>();
    }

    public string id { get; set; }
    public string invoice_batch_id { get; set; }
    public string account_id_debtor { get; set; }
    public string account_id_owner { get; set; }
    public string driver_id { get; set; }
    public string invoice_number { get; set; }
    public Nullable<decimal> balance { get; set; }
    public string load_number { get; set; }
    public Nullable<decimal> amount { get; set; }
    public string equipment_type { get; set; }
    public Nullable<System.DateTime> datetime_purchased { get; set; }
    public Nullable<System.DateTime> datetime_closed { get; set; }
    public Nullable<System.DateTime> datetime_paid { get; set; }
    public string pickup_address { get; set; }
    public string pickup_city { get; set; }
    public string pickup_county { get; set; }
    public string pickup_state { get; set; }
    public string pickup_zip { get; set; }
    public string pickup_country { get; set; }
    public Nullable<decimal> pickup_lat { get; set; }
    public Nullable<decimal> pickup_lng { get; set; }
    public string pickup_formatted_address { get; set; }
    public string delivery_address { get; set; }
    public string delivery_city { get; set; }
    public string delivery_county { get; set; }
    public string delivery_state { get; set; }
    public string delivery_zip { get; set; }
    public string delivery_country { get; set; }
    public Nullable<decimal> delivery_lat { get; set; }
    public Nullable<decimal> delivery_lng { get; set; }
    public string delivery_formatted_address { get; set; }
    public string distance_formatted { get; set; }
    public string duration_formatted { get; set; }
    public Nullable<int> distance { get; set; }
    public Nullable<int> duration { get; set; }
    public Nullable<System.DateTime> datetime_delivery { get; set; }
    public Nullable<decimal> linehaul_amount { get; set; }
    public Nullable<decimal> less_advances_amount { get; set; }
    public Nullable<decimal> detention_amount { get; set; }
    public Nullable<decimal> lumper_paid_amount { get; set; }
    public string paid_by_entity { get; set; }
    public System.DateTime datetime_created { get; set; }

    public virtual account account { get; set; }
    public virtual account account1 { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<invoice_transaction> invoice_transaction { get; set; }
}

}

"Generate DTO" does not appear in Lightbulb menu or Refactors Menu

I'm running Visual Studio 2017 version 15.9.14 with the DTO Generator extension version 1.8.1.

The README states:

Right click any entity (cs class) and choose option "Generate DTO"

However, as per the instructions, right-clicking on a class's identifier in the Code Editor window and opening the Refactors menu, or the Lightbulb menu in the left-gutter - or in the context-menu on a class in Solution Explorer or Class View - does not show the "Generate DTO" menu item.

Screenshots:

image

image

image

image

Null reference error

In VS2017, while generating a DTO from a partial class in an already-compiled project:


Microsoft Visual Studio

An exception has occurred. Please c/p stack trace to project website (https://github.com/yohney/dto-generator), with brief description of the problem.

Object reference not set to an instance of an object.

   at Microsoft.CodeAnalysis.SolutionParser.GetDocumentForSymbol(Compilation compilation, Solution solution, String name)
   at Microsoft.CodeAnalysis.SolutionParser.<WriteDto>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at DtoGenerator.Vsix.GenerateDtoCommand.<MenuItemCallback>d__13.MoveNext() in F:\git\dto-generator\src\DtoGenerator\DtoGenerator.Vsix\GenerateDtoCommand.cs:line 240
----------------------------

DTOs generated in wrong location if duplicated

I know ... bad title. But I couldn't come up with a good way of saying it in a few words.

Generate a DTO from one project into another (e.g., from a project with EF entities into a web project). Then generate using the same source class with the same name into the same target project, but in a different directory within that target project (I used /Models/Product and /Models/Recipe as my two directories).

The tool picks up the correct namespace name, but generates over the first file, which isn't in the directory you chose for the target. The first file is overwritten. Expected behavior is that the first file will be left untouched and the second would be generated in the directory requested.

Thanks.

Report the DataAnnotations from Entities

Hi,

In the generation of the DTO there is no option to report the DataAnnotations of the entity to the DTO. (Sample [Requiered] [StringLength(200)] ...)
The validator in MVC.net are based on those DataAnnotation. Without them it do not work.
Thoses Dataannotations are in properties.AttributeLists from syntaxTree.

I have develop it on my side if you want than I add this option (with a checkbox in the second screen) in your code, please add me as contributor.

NRE when creating DTOs from EF-generated files

I installed the 1.2 version of the extension, which is what's available on the VS Extensions listing.

I have a Database-first EF6 model with each Entity class existing in its own T4-generated .cs file.

I right-clicked on such a file and told it to generate the DTO in another project and gave the DTO the same name as the original entity instead of the auto-generated name (e.g. "Foo" instead of "FooDTO"), after clicking OK I got this error message:

   ---------------------------
   Microsoft Visual Studio
   ---------------------------
   An exception has occurred

   Object reference not set to an instance of an object.
   ---------------------------
   OK   
   ---------------------------

I get the error regardless of what name I choose the DTO.

Also, interestingly, the Destination Project drop-down list shows the same project twice, but not all projects.

Error generating DTO

An error message popped up while generating a DTO, giving me this site address and asking for details. So here ya go.

Message box said:

---------------------------
Microsoft Visual Studio
---------------------------
An exception has occurred. Please c/p stack trace to project website (https://github.com/yohney/dto-generator), with brief description of the problem.

Source code to parse must contain exactly one class declaration!
---------------------------
OK   
---------------------------

Unfortunately, the source code did contain exactly one class declaration.

Source class file was:


//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Manual changes to this file may cause unexpected behavior in your application.
//     Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;

namespace BER.MenuHub.Data
{
   public partial class MenuItemDataChange : IHasIdentity<System.Guid>
   {
      partial void Init();

      /// <summary>
      /// Default constructor. Protected due to required properties, but present because EF needs it.
      /// </summary>
      protected MenuItemDataChange()
      {
         IsDone = false;

         Init();
      }

      /// <summary>
      /// Public constructor with required data
      /// </summary>
      /// <param name="_propertyname"></param>
      /// <param name="_responsibledepartment"></param>
      /// <param name="_isdone"></param>
      /// <param name="_menuitem"></param>
      /// <param name="_changeset"></param>
      public MenuItemDataChange(string _propertyname, string _responsibledepartment, MenuItem _menuitem, MenuItemChangeSet _changeset, bool _isdone = false)
      {
         if (string.IsNullOrEmpty(_propertyname)) throw new ArgumentNullException(nameof(_propertyname));
         PropertyName = _propertyname;
         if (string.IsNullOrEmpty(_responsibledepartment)) throw new ArgumentNullException(nameof(_responsibledepartment));
         ResponsibleDepartment = _responsibledepartment;
         IsDone = _isdone;
         if (_menuitem == null) throw new ArgumentNullException(nameof(_menuitem));
         MenuItem = _menuitem;

         if (_changeset == null) throw new ArgumentNullException(nameof(_changeset));
         ChangeSet = _changeset;

         Init();
      }

      /// <summary>
      /// Static create function (for use in LINQ queries, etc.)
      /// </summary>
      /// <param name="_propertyname"></param>
      /// <param name="_responsibledepartment"></param>
      /// <param name="_isdone"></param>
      /// <param name="_menuitem"></param>
      /// <param name="_changeset"></param>
      public static MenuItemDataChange Create(string _propertyname, string _responsibledepartment, MenuItem _menuitem, MenuItemChangeSet _changeset, bool _isdone = false)
      {
         return new MenuItemDataChange(_propertyname, _responsibledepartment, _menuitem, _changeset, _isdone);
      }

      // Persistent properties

      /// <summary>
      /// Identity, Required, Indexed
      /// </summary>
      public Guid Id { get; set; }

      /// <summary>
      /// Required, Max length = 50
      /// </summary>
      public string PropertyName { get; set; }

      /// <summary>
      /// Max length = 200
      /// </summary>
      public string LastUpdatedBy { get; set; }

      public DateTime? LastUpdatedDate { get; set; }

      /// <summary>
      /// Required, Max length = 50
      /// </summary>
      public string ResponsibleDepartment { get; set; }

      /// <summary>
      /// Max length = 4000
      /// </summary>
      public string Comments { get; set; }

      /// <summary>
      /// Required, Default value = false
      /// </summary>
      public bool IsDone { get; set; }

      // Persistent navigation properties

      public virtual MenuItem MenuItem { get; set; }  // Required
      public virtual MenuItemChangeSet ChangeSet { get; set; }  // Required
   }
}

Stack trace was:


   at DtoGenerator.Logic.Infrastructure.EntityParser.FromSyntaxTree(SyntaxTree syntaxTree)
   at DtoGenerator.Logic.Infrastructure.EntityParser.<FromDocument>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at DtoGenerator.Logic.UI.EntityViewModel.<CreateRecursive>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at DtoGenerator.Logic.UI.EntityViewModel.<CreateRecursive>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at DtoGenerator.Logic.UI.PropertySelectorViewModel.<Create>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at DtoGenerator.Vsix.GenerateDtoCommand.<MenuItemCallback>d__13.MoveNext() in F:\git\dto-generator\src\DtoGenerator\DtoGenerator.Vsix\GenerateDtoCommand.cs:line 235
----------------------------

Hope this helps track down the problem. BTW, it's not uncommon for me to get errors while generating DTOs with this tool, but it does remove enough of the drudgery that I haven't given up on it :-)

Thanks for your hard work.

Selections cut off on 4k Monitor

I am unable to view some of the parameter selections on my screen. No matter how big or small I make the window, it doesn't make the options available for viewing.

here

Error while generating DTO - Sequence contains no elements

Steps to reproduce: Right click on an entity class-> Generate DTO -> Select path of another project in the same solution-> Name DTO class-> Click OK.

Exception Thrown:
An exception has occurred. Please c/p stack trace to project website......
Sequence contains no elements
image

Stack trace:
at System.Linq.Enumerable.Single[TSource](IEnumerable1 source)
at DtoGenerator.Logic.Infrastructure.EntityParser.GetRelatedEntity(PropertyDeclarationSyntax p)
at DtoGenerator.Logic.Infrastructure.EntityParser.<>c.b__5_10(PropertyDeclarationSyntax p)
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at DtoGenerator.Logic.Infrastructure.EntityParser.FromSyntaxTree(SyntaxTree syntaxTree)
at DtoGenerator.Logic.Infrastructure.EntityParser.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at DtoGenerator.Logic.UI.EntityViewModel.d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at DtoGenerator.Logic.UI.PropertySelectorViewModel.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at DtoGenerator.Vsix.GenerateDtoCommand.d__13.MoveNext() in C:\git\dto-generator\src\DtoGenerator\DtoGenerator.Vsix\GenerateDtoCommand.cs:line 235`

Error with Visual Studio 2017

Class:
namespace ProductsApp.Models
{
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string Category { get; set; }
public decimal Price { get; set; }
}
}

Error:

at Microsoft.CodeAnalysis.SolutionParser.GetPossibleProjects(Document doc)
at DtoGenerator.Vsix.GenerateDtoCommand.d__13.MoveNext() in F:\git\dto-generator\src\DtoGenerator\DtoGenerator.Vsix\GenerateDtoCommand.cs:line 208

Move C# templating to customizable T4 templates

The templates for the DTO and Mapper are contained in this file: https://github.com/yohney/dto-generator/blob/master/src/DtoGenerator/DtoGenerator.Logic/Infrastructure/Template/Outline.cs

This file is currently embedded as a resource-stream in the extension assembly which means they cannot be customized by the user.

Can these templates be defined by T4 and evaluated at runtime?

Or better yet: generate T4 templates we can embed directly in our projects?

Non-nullables assign null in SelectorExpression

Thanks for the project -- this is turning out to be quite a time-saver! An issue, though: please check the nullability of an assignment in the SelectorExpression. I'm getting things like

OwnerId = p.Owner != null ? p.Owner.Id : null

when OwnerId is a straight int, not an int?. To simplify, the ternary could output

OwnerId = p.Owner != null ? p.Owner.Id : default(TYPE)

where TYPE is the target type (in this case, default(int)) and all would be excellent.

Thanks again.

Wrong namespaces in .NET Core

GetPossibleProjects() includes a ..NETCoreApp,Version=v1.1 or ..NET Framework 4.6.2 suffix for every .NET Core project in the solution. 'Classic' .NET projects show as expected.

This causes the DTOs to have the wrong namespace and a "using unknown;" statement.

image

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.