Thursday, March 10, 2011

Table types doesn’t support Entity Framework

 

/// <summary>
///
Saves bulk employees at once
/// </summary>
/// <param name="dtContainer"></param>
public void SaveEmployees(DataTable dtContainer) //this dtContainer exactly match your table type which is created in sqlserver
{
using (var context = DataObjectFactory.CreateContext())
{
SqlParameter param = new SqlParameter("@YourSPParameterNameHere", SqlDbType.Structured);
param.Value = dtContainer;
param.TypeName = "EMPItemsType"; //Name of you tabletype which you have created in sqlserver
EntityConnection entityConnection = (EntityConnection)context.Connection;
SqlConnection sqlConnection = (SqlConnection)entityConnection.StoreConnection; //getting sqlconnection string from EntityConnection
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand("SaveEmployees", sqlConnection); // specify the sp name
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.Add(param);
int result = sqlCommand.ExecuteNonQuery();
sqlConnection.Close();
}
}

No comments:

Post a Comment