locked
How to share Entity Code between Web and SL project RRS feed

  • Question

  • I have an Entity Class.  I use something like this to set the default values of the Entity:

    public partial class EmailFolderEntity
        {
    
            partial void OnCreated()
            {
                this._createdBy = "SomeUser";
                this._updatedBy = this._createdBy;
            }
        }

    This works just fine as long as the code is in the SL Project.  However, when I try to put it into the Shared Folder with the .shared.cs name, the OnCreated() no longer shows up as available and will not compile.  Other properties of the Entity do show up, but not the OnCreated().

    I am not sure what the deal is with this.  The reason I need it on the server is that sometimes the Entities are created on the server, and I need the default values set whether it is created on the client or on the server.

    Greg

    Sunday, October 31, 2010 9:54 PM

Answers

  • You could write something like this (unfortunately common in shared classes).

    #if !SILVERLIGHT
      public EmailForlderEntity()
      {
        this.OnCreated();
      }
    #endif

    (edit: you might have to add the 'partial' stub in there too)

    Monday, November 1, 2010 10:41 AM

All replies

  • I don't know why you what that, but sl run on client. If you want data from server, you should using service (WCF service, web service...).

    Sunday, October 31, 2010 11:23 PM
  • You could write something like this (unfortunately common in shared classes).

    #if !SILVERLIGHT
      public EmailForlderEntity()
      {
        this.OnCreated();
      }
    #endif

    (edit: you might have to add the 'partial' stub in there too)

    Monday, November 1, 2010 10:41 AM
  • This is what I came up with:

        public partial class TestEntity
        {
    #if !SILVERLIGHT
            public TestEntity()
            {
                if(this.CreatedOn == null)
                 SetDefaults();
            }
    #else
            partial void OnCreated()
            {
                SetDefaults();
            }
    #endif
            void SetDefaults()
            {
                this.CreatedOn = System.DateTime.Now;
            }
        }
    Wednesday, November 3, 2010 5:56 PM