la mia domanda è abbastanza semplice e ho cercato molte volte una risposta, ma non sono riuscito a trovare una soluzione. Questo non sembra uno scenario insolito, tuttavia, quindi se sto trascurando qualcosa di semplice o c'è un riferimento là fuori che ho trascurato che affronta il mio problema, sarei grato per qualche consiglio! Ecco qui...
Nel tentativo di connettermi a un database esistente, fuori sede tramite il mio nuovo progetto .Net Core. Ho seguito le istruzioni per il reverse engineering qui: https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html
Queste istruzioni funzionano per un db sul mio computer locale, ma quando eseguo Scaffold-DbContext con una stringa di connessione a un database DNS per un server fuori sito, crea il contesto ma non le entità. Quindi il mio file di classe di contesto è simile al seguente:
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
namespace CensusApi.Models
{
public partial class CensusDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
optionsBuilder.UseSqlServer(@"Server=database.dns.org,[port];Database=mydatabase;Integrated Security=False;User ID=myuser;Password=mypassword;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
// Unable to generate entity type for table 'dbo.LANDING_DEMOGRAPHICS_2010'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.LANDING_ECONOMIC_2007_2011'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.LANDING_STATE_FIPS'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.LANDING_ZIP_STATE'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.SAMAIN_ZIP_STATE'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.STAGE_HOUSEHOLDS'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.STAGE_HOUSING_OCCUPANCY'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.STAGE_MEDIAN_AGE'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.STAGE_MEDIAN_INCOME'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.STAGE_POPULATION'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.STAGE_POPULATION_BY_RANGE'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.STAGE_RACE'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.STAGE_RACE_HISPANIC_AND_LATINO'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.STAGE_RELATIONSHIP'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.STAGE_ZIP_STATE'. Please see the warning messages.
// Unable to generate entity type for table 'dbo.LogShipStatus'. Please see the warning messages.
}
}
La finestra ErrorList fa riferimento al #warning sulla riga 11 del codice sopra (ovvero l'avviso per proteggere le informazioni potenzialmente sensibili nella stringa di connessione). Mi rendo conto che il prossimo passo dopo aver fatto questo reverse engineering è quello di re-localizzare la stringa di connessione, e che #warning sembra essere un avvertimento generico e non un ostacolo al processo di reverse engineering.
Le credenziali che ho provato includevano l'utente sa e un utente con restrizioni. Entrambi hanno gli stessi risultati, quindi non sembra essere un problema di autorizzazioni.
C'è un metodo o una struttura diversa che dovrei usare per connettermi a un server esterno?
Qualsiasi idea o feedback sarebbe molto apprezzato!
Assicurati che le tue tabelle abbiano le chiavi primarie.
Stavo ricevendo questo esatto messaggio di errore con una sola tabella nel mio database, ho capito che avevo dimenticato la chiave primaria e dopo che ho eseguito di nuovo il comando DbScaffold, funzionava bene.