Giter Club home page Giter Club logo

Comments (8)

miket4uw avatar miket4uw commented on September 10, 2024 1

I am closing my issue since the Dapper Crud Generator extension seems intended to work with a .Net Framework project. I am using a .Net Core project. I can use the provided error message to obtain the stubbed code for inclusion into my project. Thank you.

from dapper.crud.extension.

miket4uw avatar miket4uw commented on September 10, 2024

Project Code

SQLEmploymentDB.zip

from dapper.crud.extension.

thiagoloureiro avatar thiagoloureiro commented on September 10, 2024

Hi Mike! thanks for sharing your code.
The extension reads the models (C# Classes) not SQL Files (but interesting that we can add this to the future release). so what you will need to make it work, for example, I created a class for your Address Model:

    public class Address
    {
        public int Id { get; set; }
        public string Street { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string PostalCode { get; set; }
    }

image

Result:

public class AddressRepository : IAddressRepository
{
    public async Task<IEnumerable<Address>> SelectAddress()
    {
        // Select
        using (var db = new SqlConnection(connstring))
        {
            string sql = @"SELECT Id, Street, City, State, PostalCode FROM [Address]";

            return await db.QueryAsync<Address>(sql, commandType: CommandType.Text);
        }
    }
    public async Task InsertAddress(Address address)
    {
        // Insert
        using (var db = new SqlConnection(connstring))
        {
            string sql = @"INSERT INTO [Address] (Id, Street, City, State, PostalCode) VALUES (@Id, @Street, @City, @State, @PostalCode)";

            await db.ExecuteAsync(sql, new { Id = address.Id, Street = address.Street, City = address.City, State = address.State, PostalCode = address.PostalCode }, commandType: CommandType.Text);
        }
    }
    public async Task UpdateAddress(Address address)
    {
        // Update
        using (var db = new SqlConnection(connstring))
        {
            string sql = @"UPDATE [Address] SET Id = @Id, Street = @Street, City = @City, State = @State, PostalCode = @PostalCode WHERE Id = @Id";

            await db.ExecuteAsync(sql, new { Id = address.Id, Street = address.Street, City = address.City, State = address.State, PostalCode = address.PostalCode }, commandType: CommandType.Text);
        }
    }
    public async Task DeleteAddress(Address address)
    {
        // Delete
        using (var db = new SqlConnection(connstring))
        {
            string sql = @"DELETE FROM [Address] WHERE Id = @Id";

            await db.ExecuteAsync(sql, new { address.Id }, commandType: CommandType.Text);
        }
    }
}
public interface IAddressRepository
{
    Task<IEnumerable<Address>> SelectAddress();
    Task InsertAddress(Address address);
    Task UpdateAddress(Address address);
    Task DeleteAddress(Address address);
}

from dapper.crud.extension.

thiagoloureiro avatar thiagoloureiro commented on September 10, 2024

Here there are some tricks how you generate classes from Tables:

https://stackoverflow.com/questions/5873170/generate-class-from-database-table

from dapper.crud.extension.

miket4uw avatar miket4uw commented on September 10, 2024

Thiago,

Thank you for your detailed explanation and the link for the class generation script. I created a .Net Core library and recieved a compile error message. I am guessing that the reason is that I need to create a .Net Framework library instead. I will upload my project in case you would like to take a look.

Thank you,
Mike

Error during the operation: Compiler Errors :
Line 10,28 : The type or namespace name 'Configuration' does not exist in the namespace 'Microsoft.Extensions' (are you missing an assembly reference?)
InnerException StackTrace at Dapper.Crud.VSExtension.Helpers.AssemblyHelper.BuildAssembly(String code) in C:\Projects\Dapper.Crud.Extension\Dapper.Crud.VSExtension\Helpers\AssemblyHelper.cs:line 49
at Dapper.Crud.VSExtension.Helpers.AssemblyHelper.ExecuteCode(String code, String namespacename, String classname, Boolean isstatic) in C:\Projects\Dapper.Crud.Extension\Dapper.Crud.VSExtension\Helpers\AssemblyHelper.cs:line 61
at Dapper.Crud.VSExtension.Helpers.ModelHelper.Generate(String[] content, String rawContent, String model) in C:\Projects\Dapper.Crud.Extension\Dapper.Crud.VSExtension\Helpers\ModelHelper.cs:line 10
at Dapper.Crud.VSExtension.frmExtension.GetPropertyInfos(String model) in C:\Projects\Dapper.Crud.Extension\Dapper.Crud.VSExtension\frmExtension.cs:line 277
at Dapper.Crud.VSExtension.frmExtension.GenerateCrud() in C:\Projects\Dapper.Crud.Extension\Dapper.Crud.VSExtension\frmExtension.cs:line 73 Code using System;
EmploymentLibrary.zip

from dapper.crud.extension.

thiagoloureiro avatar thiagoloureiro commented on September 10, 2024

Hi Mike, isn't for .Net Framework project only.. works for .NET Standard and .NET Core.
I will check your Zip file and get back to you here

from dapper.crud.extension.

thiagoloureiro avatar thiagoloureiro commented on September 10, 2024

image

from dapper.crud.extension.

thiagoloureiro avatar thiagoloureiro commented on September 10, 2024

I found a small bug on the component that I will fix, to make the application works I just removed temporarly the DataAccess.cs from the project to generate (there's a bug reading that file that I need to fix) then will manage. Next version I will put a for this scenario :)

from dapper.crud.extension.

Related Issues (17)

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.