优化体验之使用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类图太多,比如说上百个。。。。

 

转载于:https://www.cnblogs.com/dragon-L/p/6551134.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值