Code Monkey home page Code Monkey logo

databaseconnection's Introduction

Installation

Discord

First you need to add this in to your project folder.

After that you need to add it as an project.

Finally you need to add it as a Project Reference to your main project.

Get a local mysql database

You can go get it by downloading wamp server. Link to guide: https://www.youtube.com/watch?v=C-50GV2uUu0

You need to add the Services you create and the RContext in your Startup.cs or your Program.cs if it is a discord bot, they need to be set as a singleton like this:

Normal .net 5 or 3.1 core projects in Startup.cs

public void ConfigureServices(IServiceCollection services) {
	services.AddSingleton<RContext>();
	services.AddSingleton<MemberConnectionService>();

Discord in Program.cs

private ServiceProvider ConfigureServices() {
	ServiceCollection serviceCollection = new();
			
	serviceCollection
		.AddSingleton<RContext>()
		.AddSingleton<MemberConnectionService>(); // For Services.
}

Setting DBContext Server Connection String

You need to set the server connection under the debug tab under properties when you right click on your project.

Fluent Api

Docs for Fluent Api: https://www.entityframeworktutorial.net/efcore/fluent-api-in-entity-framework-core.aspx

If you look in the DBContext under the Data folder you will find some examples that I have taken from my bot.

Service Creation

Under the folder called Services you will find a few examples look at the MemberConnectionService.cs there is some examples on how to make one.

You can also copy the EmptyTamplateService.cs and use it.

RContext Information

The RContext.cs is located under the Data folder.

The RContext.cs is used to contact the database, using predefined functions that is described in the Repository.cs.

You need to Dependency Inject the RContext by doing this in the places where you want to contact your database here is how:

private readonly RContext _rContext;

//In order to make a ctor just write in ctor and hit tap twice.
//Ctor stands for constructor.
public CTOR(RContext rContext) {
	_rContext = rContext;
}

If you have made services then you can Dependency Inject them like this.

private readonly MemberConnectionService _memberConnectionService;

public CTOR(MemberConnectionService memberConnectionService) {
	_memberConnectionService = memberConnectionService;
}

You can Dependency Inject both of them or more like this.

private readonly MemberConnectionService _memberConnectionService;
private readonly RContext _rContext;

public CTOR(MemberConnectionService memberConnectionService, RContext rContext) {
	_memberConnectionService = memberConnectionService;
	_rContext = rContext;
}

databaseconnection's People

Contributors

killerfrienddk avatar

Stargazers

Alessandro Suha avatar  avatar

Watchers

 avatar

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.