1

If we develop a system using database first approach is it essential to draw a class diagram?

I'm using Entity Framework & I generated the Entity Data Model from the database. I have no rights to make any change in those generated model classes. (inheriting from other classes or making class abstract & etc.) Even If I made any change in those classes, All the changes are reset when I generate the EDM again.

Then Where to apply the class diagram i have drawn? I have implemented the class diagram when I develop a 3 tire standalone system. Now I'm using ASP.NET MVC 4.

I guess I don't need to bother about class diagram if I follow Database First. Am I correct? I am really confusing with those tire architecture & MVC...

Chamith
  • 129
  • 1
  • 13
  • The generated classes are partial so you can keep your changes from getting overwritten as described [here](http://stackoverflow.com/questions/15621656/data-annotations-with-entity-framework-5-0-database-first). If you want to start with classes, look into the code first work flow. – Steve Greene May 09 '17 at 18:37

2 Answers2

0

Your Entity Data Model are repressing the tables. You can use repository pattern to access them into controller. You can also create view models(class) based on requirement and update data from Entity Data Model into view model.This will decoupled your data layer and domain.

Vivek
  • 9
  • 2
0

Example :

SQL Script:

  CREATE DATABASE TEST
GO
USE [TEST]
GO

CREATE TABLE [dbo].[Org](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [varchar](150) NULL,
    [Website] [varchar](50) NULL,
    [Address] [nvarchar](250) NULL,
 CONSTRAINT [PK_Org] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
 IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Entity/Model:

  [Table("Org")]
   public class Org
    {
        [Key]
        public int Id { get; set; }
        [Required)]
        public string Name { get; set; }
        public string Website { get; set; }
        public string Address { get; set; }
    }
**DbContext:**

    public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext() : base("DefaultConnection")
    {           
    }
  public DbSet<Org> Orgs { get; }

}

But there is one problem .When you change you DB then Update your model/Entity manually.

Ashiquzzaman
  • 5,129
  • 3
  • 27
  • 38