Introduction
In this blog we will see how to perform add range operation using entity framework.
Step 1: Create console application
Employee.cs
- namespace AddRangeEFApp
- {
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Data.Entity.Spatial;
- [Table("Employee")]
- public partial class Employee
- {
- public int Id { get; set; }
- [StringLength(50)]
- public string FirstName { get; set; }
- [StringLength(50)]
- public string LastName { get; set; }
- }
- }
Employeecontext.cs
- namespace AddRangeEFApp
- {
- using System;
- using System.Data.Entity;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Linq;
- public partial class EmployeeContext : DbContext
- {
- public EmployeeContext()
- : base("name=EmpConn")
- {
- }
- public virtual DbSet<Employee> Employees { get; set; }
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- modelBuilder.Entity<Employee>()
- .Property(e => e.FirstName)
- .IsUnicode(false);
- modelBuilder.Entity<Employee>()
- .Property(e => e.LastName)
- .IsUnicode(false);
- }
- }
- }


Join the conversation! Your thoughts help the community grow.