Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
583 views
in Technique[技术] by (71.8m points)

Integrate PetaPoco v6 with asp.NET core

I am trying to use petapoco with my .NET core MVC application, I have installed petapoco compiled as stated in another answer but don't know what to do next, I searched many places but most of them had been using the previous versions of petapoco and not the latest one, Can someone please help and provide some resources link as to how am I supposed to connect it with my SQL server using a connection string, and since now their documentation suggested to use PetaPoco.DBEntityGenerator instead of T4 templates, I have no idea how to use it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Start by reading the Quick start guide

To connect to your db, you can start with the samples given:

// Normal
var db = new PetaPoco.Database("connectionStringName");

// Or the fluent configuration (PostgreSQL as an example)
var db = DatabaseConfiguration.Build()
         .UsingConnectionString("Host=127.0.0.1;Username=petapoco;Password=petapoco;Database=petapoco;Port=5001")
         .UsingProvider<PostgreSQLDatabaseProvider>()
         .UsingDefaultMapper<ConventionMapper>(m =>
         {
             m.InflectTableName = (inflector, s) => inflector.Pluralise(inflector.Underscore(s));
             m.InflectColumnName = (inflector, s) => inflector.Underscore(s);
         })
         .Create();

V6 only change the package and dropped support for some thing like T4, but you don't need the templates to start. The rest it's the same as V5


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...