Comments (8)
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.
Project Code
from dapper.crud.extension.
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; }
}
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.
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.
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.
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.
from dapper.crud.extension.
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)
- No code generated HOT 2
- Compilation Error HOT 4
- Dapper.Crud.Extension on vs 2019 HOT 1
- Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater. Line 797,21 HOT 2
- Visual Studio 2019 Community Edition Error Message HOT 2
- Projeto foi abandonado? HOT 2
- Erro ao gerar Código HOT 5
- Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations HOT 3
- Error thrown: 'IDbConnection' does not contain a definition for 'Query' HOT 1
- Add Support to C# 10 HOT 2
- Don't work with model C# 10 . CORE 6 HOT 2
- Error: Assembly and module attributes must precede all other elements HOT 4
- White box around selected line in dark theme. HOT 1
- ignoring byte type on model HOT 2
- inserted id HOT 2
- Error during the operation: Compiler Errors HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dapper.crud.extension.