Ten artykuł jest lustrzanym artykułem tłumaczenia maszynowego, kliknij tutaj, aby przejść do oryginalnego artykułu.

Widok: 23619|Odpowiedź: 0

[Źródło] Pierwszy typ ciągu atrybutu kodu EF dodaje właściwości indeksu

[Skopiuj link]
Opublikowano 23.11.2017 18:47:15 | | | |
Jeśli chcesz utworzyć indeks i przyspieszyć zapytanie, dodaj atrybut [Index] do atrybutu i automatycznie wygeneruj kod w następujący sposób:

Aktualizujemy bazę danych i błąd wygląda następująco:



System.Data.SqlClient.SqlException (0x80131904): table 'dbo. Kolumna "Telefon" w "Konto" nie może być używana jako kolumna kluczowa w indeksie.
   at System.Data.SqlClient.SqlConnection.OnError (SqlException exception, Boolean breakConnection, Action'1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError (SqlException exception, Boolean breakConnection, Action'1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   In System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
   In System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource'1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   In System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   W System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher. <NonQuery>b__0(DbCommand t, DbCommandInterceptionContext'1 c)
   In System.Data.Entity.Infrastructure.Interception.InternalDispatcher'1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func'3 operation, TInterceptionContext interceptionContext, Action'3 wykonywana, Action'3 wykonywana)
   W System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
   W System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()
   W System.Data.Entity.Migrations.DbMigrator.ExecuteSql(MigrationStatement migrationStatement, DbConnection connection, DbTransaction transaction, DbInterceptionContext interceptionContext)
   W System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(MigrationStatement migrationStatement, DbConnection connection, DbTransaction transaction transaction , DbInterceptionContext interceptionContext)
   W System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable'1 migrationStatements, DbConnection connection, DbTransaction transaction, DbInterceptionContext interceptionContext)
   W System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsWithinTransaction(IEnumerable'1 migrationStatements, DbTransaction transaction, DbInterceptionContext interceptionContext)
   W System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsWithinNewTransaction(IEnumerable'1 migrationStatements, DbConnection connection, DbInterceptionContext interceptionContext)
   W System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable'1 migrationStatements, DbConnection connection, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable'1 migrationStatements, DbConnection connection)
   na stronie System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClass32. <ExecuteStatements>b__30()
   W System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1. <Execute>b__0()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func'1 operation)
   W System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
   W System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable'1 migrationStatements, DbTransaction existingTransaction)
   W System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable'1 migrationStatements)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable'1 migrationStatements)
   W System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable'1 operations, IEnumerable'1 systemOperations, Boolean obniżanie klasy, auto booleańskie)
   na stronie System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   na stronie System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable'1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable'1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   na stronie System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
   W System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClasse. <Update>b__d()
   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   W System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
   In System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
ClientConnectionId:2b5f614b-caab-4be6-bc1b-a813b7356739
Numer błędu: 1919, Stan: 1, Klasa: 16
Stół 'dbo. Kolumna "Telefon" w "Konto" nie może być używana jako kolumna kluczowa w indeksie.


Przyczyną błędu jest fakt, że wszystkie właściwości ciągów ef domyślnie mają typ NVARCHAR(Max),

Rozwiązanie jest następujące:

Wykonaj długość ciągu





Jak pokazano na zdjęciu, stworzenie kończy się sukcesem!





Poprzedni:Jak przechowywać ciągi znaków dłuższe niż 4000 znaków w NHibernate 3.3
Następny:Tablice szyfrowania C#
Zrzeczenie się:
Całe oprogramowanie, materiały programistyczne lub artykuły publikowane przez Code Farmer Network służą wyłącznie celom edukacyjnym i badawczym; Powyższe treści nie mogą być wykorzystywane do celów komercyjnych ani nielegalnych, w przeciwnym razie użytkownicy ponoszą wszelkie konsekwencje. Informacje na tej stronie pochodzą z Internetu, a spory dotyczące praw autorskich nie mają z nią nic wspólnego. Musisz całkowicie usunąć powyższą zawartość z komputera w ciągu 24 godzin od pobrania. Jeśli spodoba Ci się program, wspieraj oryginalne oprogramowanie, kup rejestrację i korzystaj z lepszych, autentycznych usług. W przypadku naruszenia praw prosimy o kontakt mailowy.

Mail To:help@itsvse.com