2
This is my output looks like...在C#中的實體框架調用存儲過程
,這是我的後端
Beta_DatabaseEntities db = new Beta_DatabaseEntities();
table2 tb = new table2();
int ID;
string Name;
int Salary;
public void Entry()
{
ID = Convert.ToInt16(id.Text);
Name = name.Text;
Salary = Convert.ToInt32(salary.Text);
}
private void insert_Click(object sender, EventArgs e)
{
Entry();
tb.Id = ID;
tb.Name = Name;
tb.Salary = Salary;
db.table1.Add(tb);
db.SaveChanges();
db.Database.ExecuteSqlCommand("GradeEntry "+)
}
我的存儲過程:
create procedure GradeEntry
(@ID int, @name nvarchar(50), @salary int)
As
Begin
if(@salary >= 2500)
Begin
insert into Table2 values(@ID, @name, 'A+', @salary)
End
else if(@salary >= 1000)
Begin
insert into Table2 values(@ID, @name, 'A', @salary)
End
else if(@salary >= 500)
Begin
insert into Table2 values(@ID, @name, 'B', @salary)
End
else
Begin
insert into Table2 values(@ID, @name, 'Interni', @salary)
End
End
我與實體框架的工作,但找不出瞭解如何調用在C#中工作的存儲過程。我正在使用Visual Studio 2013
我只想從C#使用實體框架調用存儲過程。
使用'db.Database.ExecuteSqlCommand(「EXEC GradeEntry @ID,@ name,@salary」,id,name,salary)',其中'id','name'&'salary'是'SqlParameter's,例如'var id = new SqlParameter(「@ id」,SqlDbType.Int); id.Value = ID;' –