Suggestion while using OpenAccess ORM

4 posts, 0 answers
  1. john
    john avatar
    67 posts
    Member since:
    Jan 2012

    Posted 26 Nov 2012 Link to this post

    I used the OpenAccess ORM in some projects. I suggest whether you can consider to create some form to auto generate to LINQ code for CURD. In that case, I only select some table or some columns in form to auto generate LINQ code. If I want to create a method to return some columns in multiple table, I need to write LINQ code for join and select, then create another customized type to return. Hope you can consider it.
  2. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 29 Nov 2012 Link to this post

    Hello John,

    Thank you for your feedback.
    We are using LINQ only for reading data from the database and this covers only the Read part of the CRUD acronym.
    I am not sure how to use LINQ for Create, Update or Delete scenarios.

    Getting back to the Read scenario I can offer you some alternatives that do not require LINQ and produce clean and nice code and results:
    • You can use lazy loading of related entities. For example if a Customer has Address, you can load the customer and then access the Address property. OpenAccess will populate the data for the proper Address record automatically for you. 
    • You can load related entities eagerly if you define a Fetch Strategy. This will enable OpenAccess to generate the right statements to load the specified related objects in single query (if possible). You can find more about Fetch Strategies here.

    I hope that the information above will enable you to complete your programming tasks easier.
    If you have any additional comments or question do not hesitate to contact us again.

    Regards,
    Viktor Zhivkov
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
  3. DevCraft banner
  4. john
    john avatar
    67 posts
    Member since:
    Jan 2012

    Posted 29 Nov 2012 Link to this post

    Hi

    Current OpenAccess ORM can generate context class and entity class based on selected table with your UI in VS. My suggestion is that whether you also can generate normal CRUD method. For example, if I select a Table named Rule, it will help to generate following method:

      public void AddRuleData(Rule entity)
            {
                using (var context = new BTContext())
                {              
                    context.Add(entity);
                    context.SaveChanges();
                }
            }

     public void UpdateRuleData(Rule entity)
            {
                using (var context = new BTContext())
                {                            
                    context.AttachCopy<Rule>(entity);
                    context.SaveChanges();
                }
            }

    public List<Rule> GetAllRules()
            {
                using (var context = new BTContext())
                {
                    return context.Rules.ToList();
                }
            }

        public void DeleteRuleData(Rule entity)
            {
                using (var context = new BTContext())
                {               
                    context.Delete(entity);
                    context.SaveChanges();
                }
            }
  5. Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 04 Dec 2012 Link to this post

    Hello John,

    Thank you for your feedback.

    Can you be more specific where do you like to see these methods defined?
    Are you trying to implement some kind of a Repository pattern?
    What is the business scenario that you think the generated code will solve?

    We have several concerns about the implementation that you have provided and any details about the ideas that you have will be extremely helpful. Here are the things that we see as potential issues:
    • Add and Update methods internally call SaveChanges() and this can prevent enlisting several changes into a single transaction;
    • GetAll method should return IQueryable<T> to enable server-side filtering, paging and sorting and greatly improve the performance of the whole application. Using ToList() method will load the all entities of the current type in memory. This is widely considered as bad practice.

    Please share the business scenario that you have in mind so we can analyze your feedback or propose an alternative approach for solving the same problem.

    Regards,
    Viktor Zhivkov
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Back to Top