C# වලට හොද ORM එක මොකද්ද ?

DooA

Well-known member
  • Jun 22, 2011
    5,202
    773
    113
    ආගිය අතක් නැත
    C# වලට හොද ORM එක මොකද්ද ?

    Java වල නම් hibernate තියෙනවා එලටම ?

    ඒ වගේ මොනවද c# වලට තියෙන්නේ.

    c# + mysql වල වැඩ කරන්න. පුළුවන් ORM එකක්. ඩිරෙක්ට් class file එක මැප් කරන්න පුළුවන් එකක්. නැත්නම් හැම ක්ලාස් එකකටම mapping xml එක ලියන්න ගියාම එපා වෙනවා
     

    Jolly_Roger

    Well-known member
  • May 2, 2009
    10,600
    1,606
    113
    Colombo XOR Matara
    Class file map karanawa kiyanne mokakda?

    A simple answer is that you wrap your tables or stored procedures in classes in your programming language, so that instead of writing SQL statements to interact with your database, you use methods and properties of objects.
    In other words, instead of something like this:
    String sql = "SELECT ... FROM persons WHERE id = 10"

    DbCommand cmd = new DbCommand(connection, sql);

    Result res = cmd.Execute(); String name = res[0]["FIRST_NAME"];
    you do something like this:

    Person p = repository.GetPerson(10); String name = p.FirstName;

    or similar code (lots of variations here.) Some frameworks also put a lot of the code in as static methods on the classes themselves, which means you could do something like this instead:
    Person p = Person.Get(10);
    Some also implement complex query systems, so you could do this:

    Person p = Person.Get(Person.Properties.Id == 10);

    The framework is what makes this code possible.

    Now, benefits. First of all, you hide the SQL away from your logic code. This has the benefit of allowing you to more easily support more database engines. For instance, MS SQL Server and Oracle has different names on typical functions, and different ways to do calculations with dates, so a query to "get me all persons edited the last 24 hours" might entail different SQL syntax just for those two database engines. This difference can be put away from your logic code.
    Additionally, you can focus on writing the logic, instead of getting all the SQL right. The code will typically be more readable as well, since it doesn't contain all the "plumbing" necessary to talk to the database.
     
    Last edited:

    rhn123

    Well-known member
  • Jul 20, 2012
    759
    37
    48
    A simple answer is that you wrap your tables or stored procedures in classes in your programming language, so that instead of writing SQL statements to interact with your database, you use methods and properties of objects.
    In other words, instead of something like this:
    String sql = "SELECT ... FROM persons WHERE id = 10"

    DbCommand cmd = new DbCommand(connection, sql);

    Result res = cmd.Execute(); String name = res[0]["FIRST_NAME"];
    you do something like this:

    Person p = repository.GetPerson(10); String name = p.FirstName;

    or similar code (lots of variations here.) Some frameworks also put a lot of the code in as static methods on the classes themselves, which means you could do something like this instead:
    Person p = Person.Get(10);
    Some also implement complex query systems, so you could do this:

    Person p = Person.Get(Person.Properties.Id == 10);

    The framework is what makes this code possible.

    Now, benefits. First of all, you hide the SQL away from your logic code. This has the benefit of allowing you to more easily support more database engines. For instance, MS SQL Server and Oracle has different names on typical functions, and different ways to do calculations with dates, so a query to "get me all persons edited the last 24 hours" might entail different SQL syntax just for those two database engines. This difference can be put away from your logic code.
    Additionally, you can focus on writing the logic, instead of getting all the SQL right. The code will typically be more readable as well, since it doesn't contain all the "plumbing" necessary to talk to the database.

    Ohh Thanks for the long explanation. read it several times and was able to get something in to mind. Have to study about Nhibernate adn thinsg related to that then :)
     

    Jolly_Roger

    Well-known member
  • May 2, 2009
    10,600
    1,606
    113
    Colombo XOR Matara
    thanks machan puluwannam machan kiyapanko C# paththen Job ekak karanna ona wena igena gannaone advanced concepts monawada kiyala. jobak hari giye na bn thama. ekai.

    mulinma trainee/ASE yanna wenne ithin. ekata nam ORM ona naha echcharama. OO concepts, SQL , Diagrams ananmanan wage basic knowledge ekak thibbama athi. godak companies wala practicle test ekak thiyanawa. ekata podi test ekak denne CRUD app ekak. :):)
     

    rhn123

    Well-known member
  • Jul 20, 2012
    759
    37
    48
    mulinma trainee/ASE yanna wenne ithin. ekata nam ORM ona naha echcharama. OO concepts, SQL , Diagrams ananmanan wage basic knowledge ekak thibbama athi. godak companies wala practicle test ekak thiyanawa. ekata podi test ekak denne CRUD app ekak. :):)
    trainee ewa wadiya set wenne na machan. topjobs balanawa. thibba ewata damma. langadi SE ekakata gihin mata aduna. :lol::( interview karapu pora sorry kyalath kiwwa. ASE th experience illanawane machan.
     

    Jolly_Roger

    Well-known member
  • May 2, 2009
    10,600
    1,606
    113
    Colombo XOR Matara
    trainee ewa wadiya set wenne na machan. topjobs balanawa. thibba ewata damma. langadi SE ekakata gihin mata aduna. :lol::( interview karapu pora sorry kyalath kiwwa. ASE th experience illanawane machan.

    eka para SE yanna amarui ithin. ASE ganna ewata Exp illuwata uba interview ekedi hodai kiyala pennuwoth gannawa. :yes: practically deyak hithala karanna puluwan kiyala pennanna ona. eka interview ekak fail una kiyala nikan inna epa ban. puluwan tharam palayan. ekath pattama exp ekak ne.. :):):)
     

    rhn123

    Well-known member
  • Jul 20, 2012
    759
    37
    48
    eka para SE yanna amarui ithin. ASE ganna ewata Exp illuwata uba interview ekedi hodai kiyala pennuwoth gannawa. :yes: practically deyak hithala karanna puluwan kiyala pennanna ona. eka interview ekak fail una kiyala nikan inna epa ban. puluwan tharam palayan. ekath pattama exp ekak ne.. :):):)

    hmm ow bn. danata 4k 5k withara gihin thiyenawa. thawa yanawa ithin set wenakan. he hee wena option ekak nane :lol: