This is a migrated thread and some comments may be shown as answers.

Suggestion while using OpenAccess ORM

3 Answers 67 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
john
Top achievements
Rank 1
john asked on 27 Nov 2012, 05:28 AM
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.

3 Answers, 1 is accepted

Sort by
0
Viktor Zhivkov
Telerik team
answered on 29 Nov 2012, 07:36 PM
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.
0
john
Top achievements
Rank 1
answered on 30 Nov 2012, 02:28 AM
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();
            }
        }
0
Viktor Zhivkov
Telerik team
answered on 04 Dec 2012, 04:46 PM
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.
Tags
General Discussions
Asked by
john
Top achievements
Rank 1
Answers by
Viktor Zhivkov
Telerik team
john
Top achievements
Rank 1
Share this question
or