code_junkie

LINQ to Entities and creating a new instance of an entity

Nov 14th, 2011
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. context.Customers newCustomer = context.Customers.CreateCustomer(...);
  2. newCustomer.FirstName = firstNameTextBox.Text;
  3. newCustomer.Address.Street = streetTextBox.Text; // this is where the error is thrown
  4.  
  5. newCustomer.Address = new Address()
  6. {
  7. Street = streetTextBox.Text,
  8. // etc.
  9. };
  10.  
  11. newCustomer.Address = (from Addresses in context where ...).FirstOrDefault();
  12. if (newCustomer.Address == null)
  13. {
  14. newCustomer.Address = new Address()
  15. {
  16. Street = streetTextBox.Text,
  17. // etc.
  18. };
  19. }
Add Comment
Please, Sign In to add comment