Guest User

Untitled

a guest
Mar 24th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. using System;
  2.  
  3. namespace TestProject.Model
  4. {
  5. public class Room
  6. {
  7. public virtual int Id { get; set; }
  8. public virtual string UniqueID { get; set; }
  9. public virtual int RoomID { get; set; }
  10. public virtual float Area { get; set; }
  11.  
  12. }
  13. }
  14.  
  15. public RoomProperty()
  16. {
  17.  
  18. }
  19.  
  20.  
  21. public RoomProperty(int pRoomId, int pArea)
  22. {
  23. UniqueID = Guid.NewGuid().ToString();
  24. RoomID = pRoomId;
  25. Area = pArea;
  26. }
  27.  
  28. "ConstructorShouldNotCallVirtualMethodsRule"
  29. This rule warns the developer if any virtual methods are called in the constructor of a non-sealed type. The problem is that if a derived class overrides the method then that method will be called before the derived constructor has had a chance to run. This makes the code quite fragile.
  30.  
  31. public void SetRoomPropertyData(int pRoomId, int pArea)
  32. {
  33. UniqueID = Guid.NewGuid().ToString();
  34. RoomID = pRoomId;
  35. Area = pArea;
  36.  
  37. }
  38.  
  39. NHibernate.InvalidProxyTypeException: The following types may not be used as proxies:
  40. VITRIcadHelper.Model.RoomProperty: method SetRoomPropertyData should be 'public/protected virtual' or 'protected internal virtual'
  41.  
  42. public class Room
  43. {
  44. public virtual int Id { get; set; }
  45. public virtual string UniqueID { get; set; }
  46. public virtual int RoomID { get; set; }
  47. public virtual float Area { get; set; }
  48.  
  49. public static Room Create(int roomId, int area)
  50. {
  51. Room room = new Room();
  52. room.UniqueID = Guid.NewGuid().ToString();
  53. room.RoomID = roomId;
  54. room.Area = area;
  55. return room;
  56. }
  57. }
Add Comment
Please, Sign In to add comment