1 Creating an Entity class:
Public Partial classNewscategory:iaggregationroot { Publicnewscategory () {} PublicGuid Id {Get;Set; } Public stringCategoryName {Get;Set; } Public BOOLIsdel {Get;Set; } Public stringCode {Get;Set; } }
2. Create a mapping partner class for an entity class
Public class Newscategorymap:ientitytypeconfiguration<newscategory> { publicvoid Configure (entitytypebuilder<newscategory> builder) { Builder. ToTable ("newscategory"); } }
3. Override the Onmodelcreating method in context to apply the partner class
Public classNewsefcorecontext:dbcontext,inewscontext { PublicDbset<newscategory> Categories {Get;Set; } protected Override voidonconfiguring (Dbcontextoptionsbuilder optionsbuilder) {//write the connection string directly and build the database. Later configured in the configuration file and used hereOptionsbuilder.usesqlserver ("Server=localhost;database=wehope; User Id=sa; Password=0"); //Optionsbuilder.usesqlserver (appsetting.getappsetting ("Dealercontext")); } protected Override voidonmodelcreating (ModelBuilder ModelBuilder) {modelbuilder.applyconfiguration<NewsCategory> (NewNewscategorymap ()); Base. Onmodelcreating (ModelBuilder); } }
Complete.
Creating classes in Efcore implements the partner class implementation of the entity class by implementing the Ientitytypeconfiguration<t> interface Fluentapi