Reputation: 1253
I am trying to formulate a skeleton for an Add/update operation in the best possible way(performance wise)?I am thinking of the following way,what would you do?can any suggest if there is a better way?
public List<DefaultTestPlan> AssignDefaultTestplans(List<DefaultTestPlan> dtp)
{
foreach (var dtpdata in dtp)
{
if (dtpdata.SoftwareImage != null)
{
if (DoesRecordExist(dtp))
{
RemoveDefaultTestPlan(dtp);
AddDefaultTestPlan(dtp);
}
else
AddDefaultTestPlan(dtp);
}
else if (dtpdata.Keyword != null )
{
if (DoesRecordExist(dtp))
{
RemoveDefaultTestPlan(dtp);
AddDefaultTestPlan(dtp);
}
else
AddDefaultTestPlan(dtp);
}
else
{
throw new Exception("Invalid Record given..");
}
}
return dtp;
}
Upvotes: 0
Views: 38
Reputation: 17562
This is too broad to sensibly answer.
The code you have there is going to be fast - it's just a bunch of if
statements.
The speed of database access is more likely to have the more significant performance impact.
Also it sounds like you are describing an Upsert function - a feature some databases may already have.
As a side, given you seem to be a little performance concicous have a read of Which is faster?
Upvotes: 1