Click here to Skip to main content
14,240,716 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
Hello
I have an idea and i dont know what begin to do it and what about search.

When I use entity frame work model in project,i should create classes for each table,that have some method to modify database like update-delete-Insert-select.

My idea is create a classlibrary or other in ASP.NET, that when execute it, view all tables from database model,so when I choose a table and click on run button,then class and methods of it generated with name and specific location.

For example:table1(id,name,family) class=table1class location=/myfolder methods=save,update,delete.

Now, is there any solution about it? What do I search? How begin it?

Thank you in advance.

What I have tried:

Create a classlibrary to generate class for tables in entity frame work.classes to modify database.
Posted
Updated 4-Feb-16 10:29am
v2
Comments
PIEBALDconsult 4-Feb-16 17:52pm
   
"i should create classes for each table,that have some method to modify database like update-delete-Insert-select"

I disagree; please don't do that.
JamesHurburgh 4-Feb-16 19:03pm
   
Have a look at something like this to get you started: http://www.codeproject.com/Articles/33331/Introduction-to-the-Entity-Framework
NewWebDesigner 5-Feb-16 0:23am
   
please read the coment i write for solution1.
Rate this:
Please Sign up or sign in to vote.

Solution 4

Sounds like what you are after is using T4[^] (Text Template Transformation Toolkit) to generate your code. Basically, you will start with a template of the code you need for your functionality, then you'll open up a connection to the database to read the table structures in - there are different ways of doing this depending on the database you are using, and finally you will apply this information to your template. Start with the page I linked to and then work outwards from there.
   
Comments
Stefan_Lang 5-Feb-16 6:25am
   
Wow, I didn't even know such a thing existed. Have a 5.
Pete O'Hanlon 5-Feb-16 7:06am
   
Thanks - I am the saddest of the sad for knowing things like this exist :)
NewWebDesigner 7-Feb-16 1:48am
   
what about CodeDom NameSpace?
Pete O'Hanlon 7-Feb-16 3:12am
   
What about it? You don't need it with T4.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Follow some sort of repository pattern. Have a repository in between of your entity framework and business extended from a generic base class containing all those common methods.

Following is an example of such interface. You need to write the concrete generic methods as well.

public interface IRepository<T> where T : class
{
    Task<T> Create(T entity);

    T Read(Guid Id);

    T Update(T entity);

    T Delete(Guid Id);
}
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

Have a look at something like this to get you started:
Introduction to the Entity Framework[^]
   
Comments
NewWebDesigner 5-Feb-16 0:22am
   
I know this.You dont know my question.
I want to create a class that generate a specific class with method and property.

I dont have problem with entity framework and will create classes.i want to create a tool,that this create class otherwise i write codes.Like use CodeDom NameSpace.
Stefan_Lang 5-Feb-16 6:11am
   
That is the key, isn't it? Knowing the question. Do you?
Stefan_Lang 5-Feb-16 6:16am
   
Ok, I'll offer a little more info than my last comment: the issue you are describing already involves the solution that you are thinking of. But you failed to describe the original problem or task that this solution is meant to solve. Your solution doesn't appear practical to us, therefore the only advice we can offer so far is not to do 'it' this way. However, since we don't really now what 'it' is, we can't describe a better alternative other than through generic answers such as this solutuion.

If you want more helpful answers, you need to offer more details about your original problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100