split single project into a multiple project solution












0















We have a single project which we are going to split into a multiple project solution. we are going to take the Entities and put them in a new assembly



The current project has EF Core with ModelMetadata and other properties and methods.



namespace Project.Models.Entities
{
[ModelMetadataType(typeof(ContactsMetaData))]
public partial class Contacts
{
internal class ContactsMetaData
{
[EmailAddress]
public string Email { get; set; }
}

[NotMapped]
public string IsValid { get {return !string.IsNullOrEmpty(Email);} }

}
}


Since the we cannot extend a partial class from a different assembly this will not work. I am looking for another solution to do this. I have tried to extend the class but it’s not working...
Could anyone point me to a better solution?










share|improve this question























  • Have u tried Implements?

    – Joel
    Nov 16 '18 at 16:11











  • @Joel: No, not sure how..

    – Zulander
    Nov 16 '18 at 16:17











  • You can implement another class by using : syntax. Google it

    – Joel
    Nov 16 '18 at 16:57
















0















We have a single project which we are going to split into a multiple project solution. we are going to take the Entities and put them in a new assembly



The current project has EF Core with ModelMetadata and other properties and methods.



namespace Project.Models.Entities
{
[ModelMetadataType(typeof(ContactsMetaData))]
public partial class Contacts
{
internal class ContactsMetaData
{
[EmailAddress]
public string Email { get; set; }
}

[NotMapped]
public string IsValid { get {return !string.IsNullOrEmpty(Email);} }

}
}


Since the we cannot extend a partial class from a different assembly this will not work. I am looking for another solution to do this. I have tried to extend the class but it’s not working...
Could anyone point me to a better solution?










share|improve this question























  • Have u tried Implements?

    – Joel
    Nov 16 '18 at 16:11











  • @Joel: No, not sure how..

    – Zulander
    Nov 16 '18 at 16:17











  • You can implement another class by using : syntax. Google it

    – Joel
    Nov 16 '18 at 16:57














0












0








0








We have a single project which we are going to split into a multiple project solution. we are going to take the Entities and put them in a new assembly



The current project has EF Core with ModelMetadata and other properties and methods.



namespace Project.Models.Entities
{
[ModelMetadataType(typeof(ContactsMetaData))]
public partial class Contacts
{
internal class ContactsMetaData
{
[EmailAddress]
public string Email { get; set; }
}

[NotMapped]
public string IsValid { get {return !string.IsNullOrEmpty(Email);} }

}
}


Since the we cannot extend a partial class from a different assembly this will not work. I am looking for another solution to do this. I have tried to extend the class but it’s not working...
Could anyone point me to a better solution?










share|improve this question














We have a single project which we are going to split into a multiple project solution. we are going to take the Entities and put them in a new assembly



The current project has EF Core with ModelMetadata and other properties and methods.



namespace Project.Models.Entities
{
[ModelMetadataType(typeof(ContactsMetaData))]
public partial class Contacts
{
internal class ContactsMetaData
{
[EmailAddress]
public string Email { get; set; }
}

[NotMapped]
public string IsValid { get {return !string.IsNullOrEmpty(Email);} }

}
}


Since the we cannot extend a partial class from a different assembly this will not work. I am looking for another solution to do this. I have tried to extend the class but it’s not working...
Could anyone point me to a better solution?







c# entity-framework asp.net-core ef-core-2.1






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 16:09









ZulanderZulander

187316




187316













  • Have u tried Implements?

    – Joel
    Nov 16 '18 at 16:11











  • @Joel: No, not sure how..

    – Zulander
    Nov 16 '18 at 16:17











  • You can implement another class by using : syntax. Google it

    – Joel
    Nov 16 '18 at 16:57



















  • Have u tried Implements?

    – Joel
    Nov 16 '18 at 16:11











  • @Joel: No, not sure how..

    – Zulander
    Nov 16 '18 at 16:17











  • You can implement another class by using : syntax. Google it

    – Joel
    Nov 16 '18 at 16:57

















Have u tried Implements?

– Joel
Nov 16 '18 at 16:11





Have u tried Implements?

– Joel
Nov 16 '18 at 16:11













@Joel: No, not sure how..

– Zulander
Nov 16 '18 at 16:17





@Joel: No, not sure how..

– Zulander
Nov 16 '18 at 16:17













You can implement another class by using : syntax. Google it

– Joel
Nov 16 '18 at 16:57





You can implement another class by using : syntax. Google it

– Joel
Nov 16 '18 at 16:57












2 Answers
2






active

oldest

votes


















0














I think there's more than one way to do it and you will have to make some design decisions. I assume you want the repository assembly to only be concerned with accessing the database through entity framework. But the business object needs additional properties like email address. You can decouple the database objects from the domain object. You could start with an interface that describes your contact entities.



public interface IContact
{
// properties based on the Contacts you are working with
}


Then you could use a partial class in the repository assembly to state that Contacts implements the IContact interface.



public partial class Contacts : IContact
{

}


But you really need a contact with email, so describe that requirement with another interface.



public interface IContactWithEmail
{
string FirstName { get; set; }
string LastName { get; set; }
string Email { get; set; }
}


And inject the IContact dependency in the implementation.



public class ContactWithEmail : IContactWithEmail
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }

public ContactWithEmail(IContact contact, string email)
{
FirstName = contact.FirstName;
LastName = contact.LastName;
Email = email;
}
}





share|improve this answer































    0














    What you miss here is the entire concept of inheritance.



    Here you can find some usefull info about it and object oriented programming in general:



    https://en.wikipedia.org/wiki/Object-oriented_programming
    https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341582%2fsplit-single-project-into-a-multiple-project-solution%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      I think there's more than one way to do it and you will have to make some design decisions. I assume you want the repository assembly to only be concerned with accessing the database through entity framework. But the business object needs additional properties like email address. You can decouple the database objects from the domain object. You could start with an interface that describes your contact entities.



      public interface IContact
      {
      // properties based on the Contacts you are working with
      }


      Then you could use a partial class in the repository assembly to state that Contacts implements the IContact interface.



      public partial class Contacts : IContact
      {

      }


      But you really need a contact with email, so describe that requirement with another interface.



      public interface IContactWithEmail
      {
      string FirstName { get; set; }
      string LastName { get; set; }
      string Email { get; set; }
      }


      And inject the IContact dependency in the implementation.



      public class ContactWithEmail : IContactWithEmail
      {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string Email { get; set; }

      public ContactWithEmail(IContact contact, string email)
      {
      FirstName = contact.FirstName;
      LastName = contact.LastName;
      Email = email;
      }
      }





      share|improve this answer




























        0














        I think there's more than one way to do it and you will have to make some design decisions. I assume you want the repository assembly to only be concerned with accessing the database through entity framework. But the business object needs additional properties like email address. You can decouple the database objects from the domain object. You could start with an interface that describes your contact entities.



        public interface IContact
        {
        // properties based on the Contacts you are working with
        }


        Then you could use a partial class in the repository assembly to state that Contacts implements the IContact interface.



        public partial class Contacts : IContact
        {

        }


        But you really need a contact with email, so describe that requirement with another interface.



        public interface IContactWithEmail
        {
        string FirstName { get; set; }
        string LastName { get; set; }
        string Email { get; set; }
        }


        And inject the IContact dependency in the implementation.



        public class ContactWithEmail : IContactWithEmail
        {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }

        public ContactWithEmail(IContact contact, string email)
        {
        FirstName = contact.FirstName;
        LastName = contact.LastName;
        Email = email;
        }
        }





        share|improve this answer


























          0












          0








          0







          I think there's more than one way to do it and you will have to make some design decisions. I assume you want the repository assembly to only be concerned with accessing the database through entity framework. But the business object needs additional properties like email address. You can decouple the database objects from the domain object. You could start with an interface that describes your contact entities.



          public interface IContact
          {
          // properties based on the Contacts you are working with
          }


          Then you could use a partial class in the repository assembly to state that Contacts implements the IContact interface.



          public partial class Contacts : IContact
          {

          }


          But you really need a contact with email, so describe that requirement with another interface.



          public interface IContactWithEmail
          {
          string FirstName { get; set; }
          string LastName { get; set; }
          string Email { get; set; }
          }


          And inject the IContact dependency in the implementation.



          public class ContactWithEmail : IContactWithEmail
          {
          public string FirstName { get; set; }
          public string LastName { get; set; }
          public string Email { get; set; }

          public ContactWithEmail(IContact contact, string email)
          {
          FirstName = contact.FirstName;
          LastName = contact.LastName;
          Email = email;
          }
          }





          share|improve this answer













          I think there's more than one way to do it and you will have to make some design decisions. I assume you want the repository assembly to only be concerned with accessing the database through entity framework. But the business object needs additional properties like email address. You can decouple the database objects from the domain object. You could start with an interface that describes your contact entities.



          public interface IContact
          {
          // properties based on the Contacts you are working with
          }


          Then you could use a partial class in the repository assembly to state that Contacts implements the IContact interface.



          public partial class Contacts : IContact
          {

          }


          But you really need a contact with email, so describe that requirement with another interface.



          public interface IContactWithEmail
          {
          string FirstName { get; set; }
          string LastName { get; set; }
          string Email { get; set; }
          }


          And inject the IContact dependency in the implementation.



          public class ContactWithEmail : IContactWithEmail
          {
          public string FirstName { get; set; }
          public string LastName { get; set; }
          public string Email { get; set; }

          public ContactWithEmail(IContact contact, string email)
          {
          FirstName = contact.FirstName;
          LastName = contact.LastName;
          Email = email;
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 16:54









          chadntchadnt

          728418




          728418

























              0














              What you miss here is the entire concept of inheritance.



              Here you can find some usefull info about it and object oriented programming in general:



              https://en.wikipedia.org/wiki/Object-oriented_programming
              https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)






              share|improve this answer




























                0














                What you miss here is the entire concept of inheritance.



                Here you can find some usefull info about it and object oriented programming in general:



                https://en.wikipedia.org/wiki/Object-oriented_programming
                https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)






                share|improve this answer


























                  0












                  0








                  0







                  What you miss here is the entire concept of inheritance.



                  Here you can find some usefull info about it and object oriented programming in general:



                  https://en.wikipedia.org/wiki/Object-oriented_programming
                  https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)






                  share|improve this answer













                  What you miss here is the entire concept of inheritance.



                  Here you can find some usefull info about it and object oriented programming in general:



                  https://en.wikipedia.org/wiki/Object-oriented_programming
                  https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 16 '18 at 18:31









                  moro91moro91

                  158114




                  158114






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341582%2fsplit-single-project-into-a-multiple-project-solution%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud

                      Zucchini