image

20230919 .NET interview experience

20230919 .NET interview experience SQL Main difference between IQuerable and IEnumerable? https://stackoverflow.com/questions/252785/what-is-the-difference-between-iqueryablet-and-ienumerablet So the difference between IQueryable and IEnumerable is about where the filter logic is executed. One executes on the client side and the other executes on the database. So if you work with only in-memory data collection, IEnumerable is a good choice, but if you want to query data collection which is connected with database IQueryable is a better choice as it reduces network traffic and uses the power of SQL language. Id name, delete duplicate data Leetcode original title https://leetcode.cn/problems/delete-duplicate-emails/ DELETE p1 FROM Person p1, Person p2 WHERE p1.Email = p2.Email AND p1.Id > p2.Id Suppose ID 1, 3, 5 have the same email 1 – 1 1 – 3 1 – 5 Finally 1 is left 3 – 1 3 – 3 3 – 5 3 > 1 deleted 3 5 – 1 5 – 3 5 – 5 5 > 1, 5 > 3 deleted 5 — Cannot run on MySQL, but can run on SQL Server DELETE FROM A WHERE id NOT IN ( SELECT MIN(id) — retain the rows with the smallest id value in the name column FROM A GROUP BY name…

About .Net 6.0 In Linux and Docker containers, generate graphical verification codes without installing any dependencies! ! ! ! ! ! ! ! ! ! !

About .Net 6.0 In Linux and Docker containers, generate graphical verification codes without installing any dependencies! ! ! ! ! ! ! ! ! ! ! In the .Net Framework era, we mostly used System.Drawing to generate verification codes. There is no problem in using it in .Net 6. However, System.Drawing relies on Windows GDI+. In order to achieve cross-platform, I fell into deep thought!! Microsoft recommends using SkiaSharp as an alternative, so we started the journey of pitfalls First, install SkiaSharp Write graphics generation code. public class VerifyCodeHelper { private static span> SKFont _font; private static span> object _lock = new span> object(); private static span> readonly char [] Chars = { ‘0’,’ span>1′ ,’2′,’3′,’4′,’5′,’6′,’8′,’9′, ‘A span>’,’B’, ‘C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’,’K’, ‘ L’,’ M’ span>,’N’,’O’, ‘P’,’Q span>’,’R’, ‘S’,’T’,’U’,’V’,’W’,’X’,’Y’,’Z’ }; private static span> string GenCode(int span> num) { var code = string .Empty; var r = new Random(); for (int i = 0; i < num; i++) { code += Chars[r.Next(Chars.Length)].ToString(); } return code; } /// /// Get image digital verification code /// /// public static (string code, byte[] bytes) GetVerifyCode() { var code = GenCode(4); int width = 128 ; int height = 45 ; Random random = new (); //Create bitmap…

Doccer upload hub and configure domestic mirror source

Doccer upload hub and configure domestic mirror source

Dockcer uploads hub and configures domestic mirror source Dockcer upload hub and configure domestic mirror source 1.Dockcer upload hub To upload a local Docker image to the Docker image warehouse, you can follow the following steps: linux environment 1. Create user First, make sure you have created an account on Docker Hub or another container registry and have permission to upload images. 2. Login user Log in to Docker Hub or other container registry in a command line terminal. Use the docker login command and enter your username and password. For example: docker login 3.Set hub label Next, use the following command to mark the local image with the full name in the target registry. You can use the docker images command to view a list of all local images and find the name and label of the image you want to upload. For example: docker images REPOSITORY TAG IMAGE ID CREATED SIZE my_image latest abcdef123456 1 week ago 550MB Use the following command to tag the image: docker tag my_image:latest your-docker-username/my_image:latest Replace your-docker-username with your username in the image repository. 4. Mirror upload Finally, upload the tagged image to the registry using the following command: docker push your-docker-username/my_image:latest This…

5. Use logs + custom global exception filters

5. Use logs + custom global exception filters When I first started writing the article and encapsulating the Base class, I added a trycatch exception block, but I didn’t record the log at that time and just returned it. A friend advised me not to eat Exception Actually no, the project has just started and I think it’s better to do the overall structure first. It’s like building a building. Build the building first, and then beautify and perfect it step by step. The basic warehousing model is already ok, and Autofac has been injected into the implementation layer of the project. In the previous article, I created a new Test class mainly for testing, and added 4 interfaces to add, delete, modify, and check. There is no problem in executing it. This article begins with the gradual improvement of the optimization project. There are many options for logs. I remember I mentioned a few in the previous article. OK, let me repeat them again: Nlog, Log4, Serilog… What I use here is Nlog. The Log4 I used before encapsulated a Helper class. Later, when I was learning NetCore, I saw that Nlog was very easy to use. I also…

6. Swagger improvement: interface display comments + multi-version control

6.Swagger improvement: interface display comments + multi-version control On the weekend, write something simple. When creating a project in the new version of VS, you can choose to bring a swagger. However this is just basic swagger functionality. It doesn’t matter how many interfaces there are. As more and more interfaces are thrown to you, you will be confused for a while, so this article has two functions. Add comments to the swagger document Add the function of switching “versions” to swagger (which can also be understood as: allowing the interfaces of different functional modules to be displayed on one page, otherwise it will be difficult to find dozens or hundreds of interfaces together~) Right-click the project>Properties>Generate>Output>XML document file path, add the output path, I usually set the root path under the assembly, for example: The file name can be arbitrary, usually related to the project, for example: FastEasy.Readme.xml. Then go to the swagger-related Module module to add some configurations. When I started the project related to this article, I separated these injection configurations into an independent module, so if you just see this article, just look for AddSwaggerGen in Programs by default. Services.AddSwaggerGen(s => { //Multiple versions typeof(SwaggerVersion).GetEnumNames().ToList().ForEach(v =>…

Add Jwt authentication in WebApi

Add Jwt authentication in WebApi Foreword JSON Web Token (JWT) is a very lightweight specification. This specification allows us to use JWT to pass secure and reliable information between users and servers. A JWT is actually a string, which consists of three parts: header, payload and signature. The first two parts need to be Base64 encoded, and the latter part is formed by encoding the first two parts with Base64 and then encrypting it. For projects with front-end and back-end separation, most interactions use tokens for identity authentication. Today we will introduce a simple way to create and verify tokens. Project Introduction Project framework:.NET Core 3.1 Project dependencies: Swashbuckle.AspNetCore JWT Project structure: Project core code JWT helper class /// /// JWT acquisition and verification helper class /// public class JwtHelper { /// /// log /// private static Logger _logger = new Logger(); /// /// Private key configured in appsettings.json /// private static string secret = ConfigHelper.GetSectionValue(“TokenSecret”); /// /// Generate JwtToken /// /// Insensitive user data /// public static string SetJwtEncode(Dictionary payload) { try { IJwtAlgorithm algorithm = new HMACSHA256Algorithm(); IJsonSerializer serializer = new JsonNetSerializer(); IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder(); IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder); var token = encoder.Encode(payload,…

【23 Design Modes】Appearance Mode (10)

【23 Design Patterns】Appearance Mode (10) Foreword Facade Pattern, the English name is: Facade Pattern. Let’s first understand “appearance mode” from its name. When I saw the word “appearance”, I thought of the word “appearance”. The two have very similar meanings. Take dating as an example, “appearance” is very important. If you feel comfortable and likable at first glance, then there is a possibility of continuing the relationship. If it grows “three-inch nails and dead tree bark”, it will probably be choked. In this regard, “appearance” and “appearance” serve the same purpose. In a software system, to complete a function requires many interface calls, which not only increases the difficulty of development, but also increases the cost of debugging and the complexity of maintenance. Why don’t we encapsulate these interfaces again to give them a good “appearance” and make them more convenient for users? Just call one interface to complete the task of calling multiple interfaces before. This mode is very simple and easy for everyone to understand. Maybe you have used this mode more than once during the coding process, but you just don’t know the name. Definition of appearance mode Providing a consistent interface for a set of interfaces…

The real [artifact] for executing SQL statements & stored procedures. If you don’t need an ORM, choose it. It’s better than dapper.

The real [artifact] for executing SQL statements & stored procedures. If you don’t need an ORM, choose it. It’s better than dapper.

The real [artifact] for executing SQL statements & stored procedures. If you don’t need an ORM, choose it. It’s better than dapper Supports .Net Core (2.0 and above) and .Net Framework (4.0 and above) (Note: After upgrade, it can cover the early .Net Framework 4.0, and the problem of error reporting when the database field is Null has been fixed, invincible!!) This tool is provided in the IDataAccess interface. Has been adopted by many major manufacturers in the .Net circle! The namespace where IDataAccess is located is: DeveloperSharp.Framework.QueryEngine (need to reference the latest DeveloperSharp package from NuGet) It mainly provides the following four major functions: (1) Execute Sql statement (2) Execute Sp stored procedure (3) Create parameters (input/output/return) (4) Business The code for its initialization is as follows: If you are in a .Net Core environment, the code is as follows: using DeveloperSharp.Framework. QueryEngine; ————————– //In Startup.cs or Program .cs file Services.AddTransient((t) => { DatabaseInfo DIF; DIF.DatabaseType = DatabaseType.SQLServer; //Set database type DIF.ConnectionString = “Server=localhost ;Database=YZZ;Uid=sa;Pwd=123”; return DataAccessFactory.Create (DIF); }); If you are in a .Net Framework environment, the code is as follows: using DeveloperSharp.Framework. QueryEngine; ————————– DatabaseInfo DIF; DIF.DatabaseType = DatabaseType.SQLServer; //Set database type DIF.ConnectionString = “Server=localhost ;Database=YZZ;Uid=sa;Pwd=123”; IDataAccess…

Let’s talk about http request calls (Post and Get), the core part of project research and development

Let’s talk about http request calls (Post and Get), the core part of project research and development Supports .Net Core (2.0 and above) and .Net Framework (4.0 and above) 【Directory】 Foreword Post request Get request Comparison with other tools 1【Foreword】 http request calling is a function often used in development. Internally, it will be used when calling the Web Api and other formal interfaces of its own projects; externally, it will also be used when calling some third-party functional interfaces, because these third-party functions are often provided in the form of http addresses. Such as: SMS service, online translation, map service, voice intelligence, etc… So, http request calling is often a necessary core part of the development of medium and large projects, and every engineer must master it! ! 2【Post request】 http request calls are divided into two forms: Post and Get. The Post form of request is relatively complex and more commonly used. Once you understand it, the Get form will be easy to understand at a glance, so let’s first take a look at the Post form of request call. When using Post to call http, there are often four parameters that need to be set: (1) Calling…

Problems with software internationalization: C# gets the language version of the current windows system

Problems with software internationalization: C# gets the language version of the current windows system I thought it had nothing to do with internationalization and was not within the scope of software considerations. Unexpectedly, occasionally a project still cannot be avoided. Take a noteSystem.Globalization.CultureInfo.InstalledUICulture.Name This is the region code for obtaining English. That is, for zh-cn, you need to compare it with the area code dictionary. System.Globalization.CultureInfo.InstalledUICulture.NativeName The name corresponding to the region code, such as: Chinese (China) int lcid = System.Globalization.CultureInfo.CurrentCulture.LCID; Get the lcid of the language; int lcid = System. Globalization.CultureInfo.CurrentCulture.LCID; //string nam = System.Globalization.CultureInfo.InstalledUICulture.Name; //string nam2 = System.Globalization.CultureInfo.InstalledUICulture.NativeName; if (lcid == 0x804 || lcid == 0xc04 || lcid == 0x1404 || lcid==0x1004 || lcid == 0x404)//Chinese, Chinese Hong Kong, Chinese Macau, Chinese Singapore, Chinese Taiwan { XXX.Chinese; } ///English ///English -Australia ///English -Belize ///English -Canada ///English -Gabil ///English -Ireland ///English -Jamaica ///English -New Zealand ///English -the Philippines ///English -South Africa ///English -Trinidad and Tobago ///English -U.K ///English -U.S ///English -Zimbabwe if(lcid ==0x0009 || lcid ==0x0C09 || lcid ==0x2809 || lcid ==0x1009 || lcid == 0x2409|| lcid ==0x1809 || lcid ==0x2009 || lcid ==0x1409 || lcid ==0x3409 ||lcid ==0x1c09 ||lcid ==0x2c09 ||lcid ==0x0809 || lcid ==0x0409 ||lcid ==0x3009) {…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: 34331943@QQ.com

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索