c# - OOP interaction with database -


if object oriented programming focused on objects, consist of methods , data, best oop-focused approach working databases, using c#?

for example, want log using c# classes, , record logs in sql table. other factors being neutral, more "proper," object-oriented speaking, do:

  • create class what's being logged, , include methods database access
    (the methods tied closely data)

    public class activity {     public string activityproperty { get; set; }      public void sqlmethod1() {}      public void sqlmethod2() {} } 

...or,

  • create class what's being logged, , create class database access
    (methods not closely tied data, way data accessed treated object, i.e. referencing ef or orm)

    public class activity {     public string activityproperty { get; set; } }  public class sqlmethods {     public string sqlproperty { get; set; }      public void sqlmethod1(activity activityparam) { }      public void sqlmethod2(activity activityparam) { } } 

...or, perhaps better design more "object-oriented"?

generally speaking, prefer not put database access logic classes because hinders ability use them in other scenarios in data access not required. think second option more flexible one.

however, if aware of orm solutions such entity framework, suggest using 1 of those. ef takes approach closer second 1 in use pocos (plain old c# classes) , other ef classes take care of moving data objects database , back.

so overall suggestion use entity framework code first methodology.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -