Automatic class generator

Asked

Viewed 831 times

4

How do I take the BD(Oracle) entity and generate in my system a class that represents that entity?

Ex: I have this entity

Client

ID int Primary key

Name varchar(100)

And now with the tool it already generates it:

using System;
using System.Data;

namespace meu_projeto.meu_folder.classes
{
public class Cliente{

    public int ID { get; set; }
    public string name { get; set; }

  }
}

That is, generate a POCO class based on a BD(Oracle) entity, as I do?

I’m using WPF for this.

  • What have you tried? I mean, just the idea? You don’t even know where to start?

  • I haven’t done anything yet. I’m in the web search phase, among them Sopt, which for me, is the first research I do. But I am at the moment, researching also in other sources, but I believe a lot in Sopt. At the moment, I only have the idea and the request of the manager.

  • 2

    My 20 cents: search about Reflection

  • 1

    Okay, I’ll start searching from now on. I’ll give you a vote on the comment, worth 20 cents, Hehehe.

  • What I need at the moment is to read the database and bring the fields from a table. The whole question is how to identify a collection(FK N => 1 ou 1 => N ou N => N, aí uma associação no meio).

  • If you are going to use a ORM, it usually already has a function to generate entities from the database structure. For example, to generate entities using Entity Framework: http://www.asp.net/mvc/overview/older-versions-1/models-data/creating-model-classes-with-the-entity-framework-cs

  • It’s fine to make a generator. I still can’t find a way to take Fields and types from a table and generate the poco.

  • Use the Entity framework with the database first approach. Here’s a link explaining how it does: https://csharp.today/entity-framework-6-database-first-with-oracle/

  • To get names and column types from an Oracle table: select COLUMN_NAME, DATA_TYPE from ALL_TAB_COLUMNS where TABLE_NAME = 'NOME_TABELA'. What is the specific difficulty to generate POCO?

  • Dude, a while ago I made a query sql to mount the class, only it only works for SQL Server.

  • You can use the Entity Framework Code First from Database for this, it will generate all POCO Classes from your DB. https://msdn.microsoft.com/en-us/library/jj200620.aspx

Show 6 more comments

1 answer

3

With the version core of Entity Farmework it is possible to use the direct command line on Package Manager Console

Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

It is necessary to have the following packages:

Install-Package Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.Tools
Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design

However this example is for Sql Server, but I believe that for Oracle it would only use the Providers provided by Oracle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.