code_junkie

Is there a way to override the empty constructor in a class generated by LINQtoSQL?

Nov 10th, 2011
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. partial void OnCreated()
  2. {
  3. Name = "";
  4. }
  5.  
  6. // Add new partial class to extend functionality
  7. public partial class User {
  8.  
  9. // Add additional constructor
  10. public User(int id) {
  11. ID = id;
  12. }
  13.  
  14. // Add static method to initialize new object
  15. public User GetNewUser() {
  16. // functionality
  17. User user = new User();
  18. user.Name = "NewName";
  19. return user;
  20. }
  21. }
  22.  
  23. User user1 = new User(1);
  24. User user2 = User.GetNewUser();
Add Comment
Please, Sign In to add comment