In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today Xiaobian to share with you how to use Code First mode in EF to generate singular form table name related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you have some gains after reading this article, let's learn about it together.
When we want to customize some database table generation rules, we will rewrite the OnModelCreating() method to control the singular and plural forms of the generated table names. The implementation code is as follows:
using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.Entity.ModelConfiguration.Conventions;using controls generating singular table names.Model;namespace controls generating singular table names.DatabaseContext{ public class OperationContext :DbContext { /// ///constructor: inherits from parent class, used to create database /// public OperationContext() : base("OrderManagerSystem") { } public DbSet LoginRecordInfo { get; set; } /// ///ReOnModelCreating () method to solve the problem that EF uses Code First mode to generate database table names into plural numbers /// /// protected override void OnModelCreating(DbModelBuilder modelBuilder) { //Resolves the problem that EF uses Code First to generate database table names that become plural modelBuilder.Conventions.Remove(); } }}
Implement overriding the OnModelCreating() method in the OperationContext class. OperationContext class inherits from database context DbContext. Overwriting the OnModelCreating() method requires introducing the following namespace:
using System.Data.Entity.ModelConfiguration.Conventions
The above is "How to use Code First pattern to generate singular form table names in EF" All the contents of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.