Here's my DataContext Class...
public class Dealer : DataContext
{
public Table
public Table
{
get { return this.GetTable
}
public Table
public Table
public Dealer(string connection) : base(connection) { }
}
Here's the Customer Class...
[Table(Name="Customers")]
public class Customer
{
[Column(IsPrimaryKey = true, DbType = "int NOT NULL IDENTITY", IsDbGenerated = true, CanBeNull = false)]
public int CustomerID
{
get;
set;
}
[Column(CanBeNull = false)]
public string FirstName
{
get;
set;
}
[Column(CanBeNull = false)]
public string LastName
{
get;
set;
}
[Column(CanBeNull = false)]
public string SSN
{
get;
set;
}
public override string ToString()
{
return string.Concat(this.FirstName, " ", this.LastName, " ", this.SSN);
}
private EntitySet
[Association(Storage = "vehicles", OtherKey = "CustomerID", ThisKey = "CustomerID")]
public EntitySet
{
get { return this.vehicles; }
set { this.vehicles.Assign(value); }
}
//implement INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Here's the code that throws the null reference exception
private void Button_Click(object sender, RoutedEventArgs e)
{
Customer c = new Customer() { FirstName=txtbFirstName.Text, LastName = txtbLastName.Text, SSN = txtbSSN.Text };
Dealer d = new Dealer(App.connectionString);
d.Customers.InsertOnSubmit(c); ..............................// throws null reference exception.!!!
try
{
d.SubmitChanges();
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
I have googled for many hours now and i cann't figure out why its throwing null reference exception... (found alot of other posts but non of the solutions seem to work for me )
please help ...
thanks in advance.
David KPosted Apr 6, 2014, 1:28 PM
shweta for your replies ...
d.Customers is the one that is null.
my code is based on examples i saw on the web such as
http://msdn.microsoft.com/en-us/library/bb386941(v=vs.110).aspx
and none of the examples i saw require d.Customers to be instantiated.
what do you suggest ?
Lakshmanan Sethu SankaranarayanPosted Apr 6, 2014, 2:04 AM
Shweta LodhaPosted Apr 6, 2014, 1:57 AM