I want to use EF and know two way to use context for accessing data for methods of some class:
1.passing connection for each method of class:
public partial class MyEntity
{
public static int Add(MyEntityConnection context,MyEntity input)
{
context.MyEntity.AddObject(input);
context.SaveChanges();
return input.Id;
}
}
2.using context on each method independently:
public partial class MyEntity
{
public static int Add(MyEntity input)
{
using (var context = new MyEntityConnection())
{
context.MyEntity.AddObject(input);
context.SaveChanges();
return input.Id;
}
}
}
which of above or other ways to do it is better?