locked
Need to change model/database table in .Net Blazor-Server-Side app RRS feed

  • Question

  • User-2006371901 posted

    I am building a CRUD app from a Blazor serverside project that also has EntityFramework Power Tools integrated. The initial framework I am using is from an example that is already configured with authentication identity objects. The example has the stock WeatherForecast aboard, and now that I have tested everything with the registration, logins, CRUD functionalities, I want to use one of my tables in my remote database to integrate my own thing. I am confused as in MVC , you can go to the .edmx and do an "update model from database" to make changes to your modeling. 
    In the EFPT.config.json file, it shows this entry for "Tables":
    "Tables": [
    {
    "HasPrimaryKey": true,
    "Name": "[dbo].[WeatherForecast]"

    }
    ],

    ....

    ..where as the myprojectnameContext.cs class references "some' of the field names here:

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
    modelBuilder.HasAnnotation("ProductVersion", "2.2.0-rtm-35687");

    modelBuilder.Entity<WeatherForecast>(entity =>
    {
    entity.Property(e => e.Date).HasColumnType("datetime");

    entity.Property(e => e.Summary).HasMaxLength(50);

    entity.Property(e => e.UserName).HasMaxLength(50);
    });

    OnModelCreatingPartial(modelBuilder);
    }


    .... , but it's not all the fields for the WeatherForecast table, as the TemperatureC and TemperatureF fields are not present in this method, tho they are in myprojectname/WeatherForecast.cs

    namespace EndToEndDB.Data.EndToEnd
    {
    public partial class WeatherForecast
    {
    public int Id { get; set; }
    public DateTime? Date { get; set; }
    public int? TemperatureC { get; set; }
    public int? TemperatureF { get; set; }
    public string Summary { get; set; }
    public string UserName { get; set; }
    }
    }

    ...
    ..so while the authentication-identity objects are working and the CRUD functionality is too, i'd like to merely change the table to my "Products" table and the model, but very confused after reading many online tutorials and articles.

    Thanks in advance
    Ned

    Friday, March 27, 2020 6:58 PM

All replies

  • User-474980206 posted

    the EntityFramework Power Tools are only for EF 6. in EF core you use the ef core command line tools:

         https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/?tabs=dotnet-core-cli

    note: this has nothing to do with blazor, as blazor needs to do a web service call to access a database.

    Friday, March 27, 2020 8:28 PM
  • User-2006371901 posted

    OK, I am not doing a local dbase with this, it has to be remote, so I was able to proceed with the initial integrations (mainly just assgining the sql connection with SA authentication to my remote db) after the migration stage. I just need to find out how to assign my Products table to the scheme and read the appropriate fields into the model for .net core blazor.

    Friday, March 27, 2020 10:03 PM