• 优化体验之使用visual EDM之映射存储过程,datatype to Enum


    stored produce,datatype to Enum,Colored Entity,Multiple Diagrams


    一:EDM给我们提供的强大功能

    1. 存储过程的映射

    直接灌sql到database,存在着网络传输。。。 较小了网络传输。。。


    CURD,它都是用存储过程来实现的。。。。 Ctrip 5w+

    当你Student.Add的时候,你调用s的是存储过程。。。。


    ----- delete ------------------


    USE [SchoolDB]
    GO
    /****** Object: StoredProcedure [dbo].[sp_DeleteStudent] Script Date: 09/18/2016 17:07:14 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[sp_DeleteStudent]
    -- Add the parameters for the stored procedure here
    @StudentId int
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    DELETE FROM [dbo].[Student]
    where StudentID = @StudentId

    END

    ----- insert ------------------

    USE [SchoolDB]
    GO
    /****** Object: StoredProcedure [dbo].[sp_InsertStudentInfo] Script Date: 09/18/2016 17:07:39 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[sp_InsertStudentInfo]
    -- Add the parameters for the stored procedure here
    @StudentName varchar(50)
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    INSERT INTO [SchoolDB].[dbo].[Student]([StudentName])
    VALUES(@StudentName)

    SELECT SCOPE_IDENTITY() AS StudentId

    END


    ----- insert ------------------


    USE [SchoolDB]
    GO
    /****** Object: StoredProcedure [dbo].[sp_UpdateStudent] Script Date: 09/18/2016 17:07:50 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[sp_UpdateStudent]
    -- Add the parameters for the stored procedure here
    @StudentId int,
    @StudentName varchar(50)
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    Update [SchoolDB].[dbo].[Student]
    set StudentName = @StudentName
    where StudentID = @StudentId;

    END

    db.Students.Add(new Student() { StudentName = "jack12345" }); => 调用存储过程。。。


    using (SchoolDBEntities db = new SchoolDBEntities())
    {
    db.Database.Log = Console.WriteLine;

    //db.Students.Add(new Student() { StudentName = "jack12345" });

    var item = db.Students.FirstOrDefault(i => i.StudentName == "jack123");

    //item.StudentName = "jack123";

    db.Students.Remove(item);

    db.SaveChanges();
    }


    我们既可以用隐射,也可以直接使用func函数。。。。

    二:如何通过EDM将int转换成Enum。。。。


    public partial class Teacher
    {
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public Teacher()
    {
    this.Courses = new HashSet<Course>();
    }

    public int TeacherId { get; set; }
    public string TeacherName { get; set; }
    public Nullable<TeacherTypeEnum> TeacherType { get; set; }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Course> Courses { get; set; }
    }


    public enum TeacherTypeEnum : int
    {
    One = 1,
    Two = 2,
    Three = 3
    }

    using (SchoolDBEntities db = new SchoolDBEntities())
    {
    db.Database.Log = Console.WriteLine;

    db.Teachers.Add(new Teacher()
    {
    TeacherName = "洪老师",
    TeacherType = TeacherTypeEnum.Three
    });

    db.SaveChanges();
    }


    ConsoleApplication29.TestEnum

    3. 给EDM中的类图画上颜色。。。


    4. diagram类图太多,比如说上百个。。。。

  • 相关阅读:
    如何在 SQLServer 中启用 xp_cmdshell 等
    强力解决使用node版本管理工具 NVM 出现的问题(找不到 node,或者找不到 npm)
    [啃书] 预告篇
    [啃书] 第5篇
    [啃书] 第4篇
    [啃书] 第3篇
    [啃书] 第2篇
    [啃书] 第1篇
    [前端随笔][Vue] 多级菜单实现思路——组件嵌套
    [算法小练][图][拓扑排序+深度优先搜索] 平板涂色问题
  • 原文地址:https://www.cnblogs.com/dragon-L/p/6551134.html
Copyright © 2020-2023  润新知