locked
Creating A Database Using a Web API and EF RRS feed

  • Question

  • User931778073 posted

    I know that a database can be created using Entity Framework Code First approach where you first create a class and define fields within it and these fields will then be used to create the database schema. My question is, is it possible to call a Web API from the frontend and pass in the data needed to create the class and its fields then use this class to create the database schema and generate the database.

    So for example if I needed a database to create an Employee database I would call a WEB API passing in an object with all the fields necessary to create a new class then using EF code first approach create the DB. If there is a way to do this please explain or point me to a post or a blog on this subject. Thanks.

    Monday, February 8, 2021 1:52 AM

All replies

  • User1120430333 posted

    This is certainly something I would  not recommend  doing. And an ORM is not a DBA tool IMO. Just because you possibly can does not mean that you should.

    .

    Monday, February 8, 2021 12:36 PM
  • User931778073 posted

    Hi, Thanks for your reply. Why do you think that it's a bad idea to do this? What problem can it possibly cause if someone does this? I think that if no one pushes the envelope then there won't be any advancements in anything.

    Monday, February 8, 2021 1:45 PM
  • User475983607 posted

    I know that a database can be created using Entity Framework Code First approach where you first create a class and define fields within it and these fields will then be used to create the database schema. My question is, is it possible to call a Web API from the frontend and pass in the data needed to create the class and its fields then use this class to create the database schema and generate the database.

    So for example if I needed a database to create an Employee database I would call a WEB API passing in an object with all the fields necessary to create a new class using EF code first approach. If there is a way to do this please explain or point me to a post or a blog on this subject. Thanks.

    It's possible but creating dynamic code brings up other programming problems that must be solved.  How will the existing code know the new Employee database and classes exist?  

    I'm guessing you want to create a CMS?  Can you explain the problem you are trying to solve rather than the solution?

    Monday, February 8, 2021 1:59 PM
  • User931778073 posted

    Hi, Thank you for your reply. This is more or less just an attempt to learn on my part. Basically I created a project to learn how to automate things that normally would require a coder to manually create at design time. I would like to know how to create backend code using inputs from the frontend and as you can see this goes beyond just a CMS. I've been looking online but I have yet to see an article on how to create classes, variables, properties, etc. using inputs from the frontend in real time.

    Monday, February 8, 2021 2:28 PM
  • User475983607 posted

    Hi, Thank you for your reply. This is more or less just an attempt to learn on my part. Basically I created a project to learn how to automate things that normally would require a coder to manually create at design time. I would like to know how to create backend code using inputs from the frontend and as you can see this goes beyond just a CMS. I've been looking online but I have yet to see an article on how to create classes, variables, properties, etc. using inputs from the frontend in real time.

    I think you are missing the big picture.   You are replacing the Visual Studio development environment with a browser or some other client that you have not told us about.

    Let's say you were able to create the class, the table, compile the class into an assembly and load the assembly.  How will existing logic know the classes exist?  How will existing logic know how to use newly created classes? Are you planning to write the business logic in Visual Studio?

    Typically this type of design is far more involved.  The type properties are not a one to one matches to table columns.  The property names exist in a table row as data not a column.  The value of the property exists in another table with a relationship to the definition record. The data that is passed around must follow a standard format.  The format of an employee record will be the same as an order record.  The different is in format you'll have a property name like "property" with a value of "EmployeeId"  Then another property "value" that contains the Id value.

    Monday, February 8, 2021 2:59 PM
  • User1120430333 posted

    Hi, Thanks for your reply. Why do you think that it's a bad idea to do this? What problem can it possibly cause if someone does this? I think that if no one pushes the envelope then there won't be any advancements in anything.

    It's unorthodox. If you what to do what you're doing in a single page application that's one thing, but to have a Web service doing such a thing, no I can't recommend it. And besides, an ORM is not a DBA tool, and it usually leads to a software developer not fully understanding the basics of database administration  or how to effectively program against a database.

    Monday, February 8, 2021 6:40 PM