Impact of Gen-AI on IT Jobs - Growth Mindset Show
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
iOS
Java
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
1
Reply
How to maping in Code First approach
Abhishek Kumar
8y
428
1
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
Code-First will create the database tables with the name of DbSet properties in the context class - Employees and Departments in this case. You can override this convention and can give a different table name than the DbSet properties, as shown below.namespace CodeFirst_Tutorials {public class EmployeeContext: DbContext {public EmployeeDBContext(): base() {}public DbSet
Employees { get; set; }public DbSet
Departments { get; set; }protected override void OnModelCreating(DbModelBuilder modelBuilder){//Configure default schemamodelBuilder.HasDefaultSchema("Admin");//Map entity to tablemodelBuilder.Entity
().ToTable("EmployeeInfo");modelBuilder.Entity
().ToTable("DepartmentInfo","dbo");}} }As you can see in the above example, we start with the Entity
() method. Most of the time, you have to start with the Entity
() method to configure it using Fluent API. We have used ToTable() method to map Employee entity to EmployeeInfo and Department entity to DepartmentInfo table. Notice that EmployeeInfo is in Admin schema and DepartmentInfo table is in dbo schema because we have specified dbo schema for DepartmentInfo table.
Tushar Bharambe
7y
0
Can a Unique key accept more than one Null Value ?
When to use abstract class and interface?
Message