Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to produce CRUD background management interface for asp.net core entity class

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you how the asp.net core entity class produces CRUD background management interface related knowledge points, the content is detailed, the logic is clear, I believe most people still know too much about this knowledge, so share this article for your reference, I hope you can get something after reading this article, let's take a look at it.

Demonstration function

The files in the Domain directory are [entity classes]

Program.cs is the asp.net core startup code

Using FreeSql;using ojbk.Entities;var fsql = new FreeSql.FreeSqlBuilder () .UseConnectionString (FreeSql.DataType.Sqlite, @ "Data Source=test.db;Pooling=true;Max Pool Size=10") .UseAutoSyncStructure (true) .UseNoneCommandParameter (true) .UseMonitorCommand (cmd = > Console.WriteLine (cmd.CommandText + "\ r\ n")) .build (); var builder = WebApplication.CreateBuilder (args); builder.Services.AddControllersWithViews (); builder.Services.AddSingleton (fsql); builder.Services.AddEndpointsApiExplorer (); builder.Services.AddSwaggerGen () Var app = builder.Build (); if (app.Environment.IsDevelopment ()) {app.UseSwagger (); app.UseSwaggerUI ();} app.UseAuthorization (); app.MapControllers (); app.UseDefaultFiles (); app.UseStaticFiles () / * * the following is the core code * / app.UseFreeAdminLtePreview ("/", typeof (Config), typeof (Role), typeof (Menu), typeof (User), typeof (Department), typeof (Employee), typeof (Position), typeof (AppLog) Typeof (LoginLog), typeof (OprationLog), typeof (IdleScheduler.TaskInfo), typeof (IdleScheduler.TaskLog)) App.Run ()

Now that ORM has configured the entity, it is a great pleasure to use the existing conditions to facilitate the generation of background management functions!

It is a .NET Core MVC middleware extension package FreeSql.AdminLTE.dll derived from FreeSql, which dynamically generates the interface for adding, deleting, querying and modifying entities based on the AdminLTE front-end framework.

Input: entity 1, entity 2, entity 3

Output: background management function

You only need to pass in the entity to produce the management function of curd. Isn't that a little coquettish?

First send a few running pictures to try something fresh:

This is based on the entity to generate curd interface mvc middleware, development preview or simple management of data is very convenient ah. After reading the preview picture, I can't help but sigh again about the ease of use of FreeSql, the slogan: be the most convenient ORM for .NET Core! That's right. The author repeatedly mentioned: "We are simple style, not so complex usage", also verified this point. no, no, no.

Mechanism setting 1. Add and modify data

The interface generated between the middleware includes the function of adding and modifying data, and the mapping of ordinary entities to Html5 UI according to the type of attributes.

Special mapping rules:

C # Type Html5 Boolean check box enumeration drop-down Select date date Control ManyToOne Navigation Properties drop-down Select ManyToMany Navigation Properties Multiselector

Wait, wait.

What happens when an upload file control is generated?

Those who are interested can learn about the source code, which is not currently open for external configuration.

2. List query, filtering and filtering

A paged list query is provided for each entity, with 20 pieces of data per page.

In addition, support for filtering conditions is provided, based on navigation attributes (ManyToOne, ManyToMany). For example, if [position] contains [Department Department], [employee Employee], [role Role], then the UI filtered by [Category] will appear on the list page of [Job]. For more information, please see the demo diagram above, or download demo to run.

3. Delete data

The function of batch deletion is provided for each entity in the middle part.

It also supports the cascade deletion function of complex navigation attribute relationships, which does not rely on database foreign keys.

Download Demo

We have always been accustomed to using sqlite as the test library. After testing, we directly delete the directory and leave no junk data, so the following demo does not need to be modified anywhere, and the database and table are built automatically at run time.

Operating environment: .net6.0

Click download

Step one:

Dotnet restore

Step 2:

Dotnet run

Copy the listening address and open a chrome browser to paste access.

These are all the contents of the article "how to produce the CRUD background management interface for asp.net core entity classes". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report