I have an object model:
public class MyObject{ public int Prop1{get;set;} public int Prop2{get;set;} }
I use this object in a linq to sql query, for example:
var MyQuery = from.... where.... select new MyObject() { Prop1 = ... Prop2 = ... };
The problem is that sometimes Prop1 turns out to be empty in the request, and I get an error because Prop1 is null.
I add this to the class:
public class MyObject{ ... public void Init() { this.Prop1 = 0; this.Prop2 = 0; }
How to bind Init with the "just created object" event?
And, does null solve the problem by initializing object 0 in the best way to do this?
Thanks for your suggestions.
edit: I am using Prop1 in the user interface and I cannot display null, must be 0.
source share