Why can't the entity be created?

entitycrafter 1 Reputation point
2022-05-01T21:01:19.21+00:00
# Datenbank  
* tools -> options -> uncheck prevent saving changes that require ...  
* table id -> properties -> identity spec -> yes  
* Realtionships  
  
# Backend  
  
## ASP Framework Web API  
* ASP .NET Web Application (.NET Framework)  
* Web API  
* Configure for HTTPS -> Aushackerln  
* Add -> Folder  
* Add -> New Item -> Data -> ADO.NET Entity Data Model -> EF Designer from database -> next  
  * new connection -> server name ("localhost") -> database name ("Matura") -> ok -> next  
  * EF 5.0 -> next  
  * Tables auswählen -> Pluralize or singularize auswählen -> Finish  
* Manage NuGet Packages -> Swashbuckle -> latest stable (5.6) -> install  
* Rebuild  
* Controllers -> Add -> Controller -> Web API -> Web API 2 Controller with actions, using EF -> Add  
  * Model class -> Tabelle auswählen  
  * Data context class -> Add  
  
## ASP CORE Web API  
* ASP .NET Core Web API  
* 5.0 + Configure for Https aushackerln  
* Install Nuget Packages:  
    * Microsoft.EntityFrameworkCore.SqlServer 5.x  
    * Microsoft.EntityFrameworkCore.Design 5.x  
    * Microsoft.EntityFrameworkCore.Tools 5.x  
    * Swashbuckle.AspNetCore 5.x  
* Tools -> NuGet Package Manager -> Package Manager Console  
    * `Scaffold-DbContext "Server=.\SQLExpress;Database=Matura;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models`  
* Add -> Controller -> API -> MVC Conroller with actions, using EF  
* DTO Klassen erstellen  
* In Model Klassen Konstruktor hinzufügen (DTO -> Model)  
* In Controller auf DTO ändern  
* Startup.cs -> services.AddDbContext<MaturaContext>(options => { });  
  
# Frontend  
  
## JSF  
* Web Applikation  
* Web Profile anhackerln  
* Jakarta auswählen  
* webapp/WEB-INF -> new -> XML Conf File -> JSF Conf  
* web.xml -> javax to jakarta  
    * welcome-file-list tag hinzufügen  
* Swagger Definition kopieren  
    * Projektfolder -> v1.json einfügen  
* templates Folder in Projektfolder einfügen  
* pom.xml  
    * dependency  
    * plugin  
* mvn clean  
* mvn compile  
* target/generated-sources/openapi/src/main/java  
    * -> rechtsklick -> Mark Directory as -> Generated Sources Root  
* RestClientBuilder.newBuilder().baseUri(new URI("http://localhost:1342")).build(Api.class);  
  
  
## WPF  
* WPF Application  
* 5.0 Current  
* Copy Swagger JSON into Project  
* Add Service Reference  
* View Generated Code -> Copy  
* New Class -> Paste  
* Delete Service Reference  
* `User user = (User)e.Row.Item;`  
* `client.UsersAsync(user).Wait();`  
* `datagrid.ItemSource = clent.UsersAllAsync().Result;`  
* `datagrid.Items.Refresh();`  
* `Binding={Binding .}`  
* `Binding={Binding Username,UpdateSourceTrigger=PropertyChanged}`  
  
  
# Caution  
* wenn Klassen neu generieren von OpenApi -> update v1.json  
* https://learn.microsoft.com/en-us/answers/questions/832694/entity-is-already-beeing-tracked-c.html  
  
  
  
   java  
       @RequestScoped  
       @Named  
       public class LoginBean implements Serializable {  
           private BenutzerDTO user;  
         
           @PostConstruct  
           private void init() {  
               user = new BenutzerDTO();  
           }  
         
           public String login() {  
               if (user.getBenuztername().equals("admin") && user.getPasswort().equals("admin")) {  
                   HttpServletRequest request =  
       				(HttpServletRequest) FacesContext.getCurrentInstance()  
       				.getExternalContext().getRequest();  
                   request.getSession().setAttribute("user", user);  
                   return "index.xhtml?faces-redirect=true";  
               }  
               return "";  
           }  
         
           public BenutzerDTO getUser() {  
               return user;  
           }  
         
           public void setUser(BenutzerDTO user) {  
               this.user = user;  
           }  
       }  

  
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,199 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,846 Reputation points
    2022-05-01T22:09:49.627+00:00

    You don’t state which of the above options you are using or what is the issue or error. Assuming you are webapi core, the instructions are for generating EF classes from an existing database.

    What is the error you are getting from scaffold tool? Do you have the database file?

    0 comments No comments