Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you should do is finding a architecture which is fits your solution model. In general I would do validation before creating the context. If you need more validation in your application you may want to create a validation layer for this purpose.</p> <pre><code>public class RuleViolation { public string Property {get; set;} public string Message {get; set;} } public class Program { public static List&lt;RuleViolation&gt; GetRuleViolations(string[] parameters) { List&lt;RuleViolation&gt; validations = new List&lt;RuleViolation&gt;(); if(!int.TryParse(parameters[0], out new Int32())) { validations.Add(new RuleViolation{Message ="Input1 must be integer.", Property = "input1"}); } //more validation return validations; } public static void Main(string[] parameters) { var validations = GetRuleViolations(parameters); if(validations.Any()) { validations.ForEach(x=&gt; Console.WriteLine(x.Message)); return; } int input1 = int.Parse(parameters[0]); //after all your business logic are ok, then you can go to persistence layer to hit the database. using (var context = new entityTestEntities2()) { try { var allCustomers = context.setcust(null, input1); } catch(SqlException exc) { //here you might still get some exceptions but not about validation. ExceptionManager.Log(exc); //sometimes you may want to throw the exception to upper layers for handle it better over there! throw; } } } } </code></pre> <p>Hope the example make more clearer the architecture about validation logic.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload