Instantiating New Object Instance for LInq to Sql Insertion
I'm starting to learn Linq (and loving it by the way). But I'm struggling to perform a simple insertion of a single record. Below is how I think it should go. My problem is that I cannot instantiate a new instance of Address. Intellisense doesn't recognize Address. I can query Address fine by performing a simpl开发者_开发问答e select. Similarly I've had no problems using Linq to delete records from the Address table. I'm probably overlooking something pretty basic. Any ideas?
protected void InsertAddress()
{
using (SBMData2.SBMDataContext db = new SBMData2.SBMDataContext())
{
//Create a new instance of the Address object
Address addr = new Address();
//Add new values to each field
addr.Street = "foo";
addr.Apt = "foo"
addr.City = "foo";
addr.State = "foo";
addr.Zip = "foo";
//etc
//Insert the new Address object
db.Address.InsertOnSubmit(cust);
//Sumbit changes to the database
db.SubmitChanges();
}
}
If i'm not mistaken your Address
is in a different namespace.
SBMData2.Address addr = new SBMData2.Address();
Either that or add a using
statement at the top of you class.
using SBMData2;
精彩评论