O asp 5 \ core1 kullanarak benim ilk kez ve ben'Microsoft.EntityFrameworkCore.Infrastructure.IDbContextFactory`1 [TContext]' tipi parametresinin kısıtlamayı ihlal 'TContext'
DBContext bir varlık çerçevesi ayarı sorun yaşıyorum benim nesne ile bir sınıf kitaplığı var
Sonrapublic class Utilizador
{
public Utilizador()
{
}
public int id { get; set; }
}
benim sınıfına bir referans ve bir bağlamda
public class Context : DbContext
{
public Context(DbContextOptions<Context> options)
: base(options)
{
}
public DbSet<Utilizador> Utilizadores { get; set; }
}
benim package.json onun lik bir Web Api projesi var E bu ilgili varlık çerçevesi
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc.WebApiCompatShim": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview1-final" ,
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
},
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview1-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
}
Ve nihayet startup.cs
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddEntityFramework().AddEntityFrameworkSqlServer().AddDbContext<Context>(options => options.UseSqlServer(Configuration["ConnectionStrings:DefaultConnection"]));
}
komut Add-Migrations kullanılan ve benim veritabanı ve bir tablo olarak adlandırılan __MigrationsHistory yarattı ama yani benim sınıf için herhangi yaratılmış vermedi
i Eklenti göç "mycontext" kullanılmış ve her şeyi şimdi her şey ben bu hatası alıyorum Taşıma işlemini yapmaya çalışacağım, çalışmayı durdurdu:System.ArgumentException: GenericArguments[0], 'WebApiSolution.Migrations.Context', on 'Microsoft.EntityFrameworkCore.Infrastructure.IDbContextFactory`1[TContext]' violates the constraint of type 'TContext'. ---> System.TypeLoadException: GenericArguments[0], 'WebApiSolution.Migrations.Context', on 'Microsoft.EntityFrameworkCore.Infrastructure.IDbContextFactory`1[TContext]' violates the constraint of type parameter 'TContext'. at System.RuntimeTypeHandle.Instantiate(RuntimeTypeHandle handle, IntPtr* pInst, Int32 numGenericArgs, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.Instantiate(Type[] inst)
at System.RuntimeType.MakeGenericType(Type[] instantiation)
--- End of inner exception stack trace ---
at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
at System.RuntimeType.MakeGenericType(Type[] instantiation)
at Microsoft.EntityFrameworkCore.Design.DbContextOperations.FindContextFactory(Type contextType)
at Microsoft.EntityFrameworkCore.Design.DbContextOperations.FindContextTypes()
at Microsoft.EntityFrameworkCore.Design.DbContextOperations.FindContextType(String name)
at Microsoft.EntityFrameworkCore.Design.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.RemoveMigration(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsRemoveCommand.<>c__DisplayClass0_0.<Configure>b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
GenericArguments[0], 'WebApiSolution.Migrations.Context', on 'Microsoft.EntityFrameworkCore.Infrastructure.IDbContextFactory`1[TContext]' violates the constraint of type 'TContext'.
birisi işaret edebilir beni doğru yönde mi? Neyi yanlış yapıyorum, burada neyim eksik?
sayesinde
etmedi bile veritabanı için bu yöntemleri bulmak can çalıştı i bazı son sürümünde oldukça büyük değişimler ve kullanmaya zor bulmak ppl henüz ... vardı biliyorum:/ – Shakawkaw
sorunun aslında paket bağımlılıkları nd araçları, ben onu reddetti ve biraz daha l ekledi, vs yeniden başlattı ve şimdi çalışır ... belki kötü bir başvuru ya da bir şey sorun oldu ... eğer gerekirse değişiklikler daha sonra yayınlayacaktır ... teşekkürler – Shakawkaw
@Shakawkaw Mesaj gönderebilir miyim? sorununuzu tam olarak ne? Bende aynı şeyi yaşıyorum. Öğrenmek için bir öğretici ardından proje.json araçları ve bağımlılıkları ile neyin yanlış olduğunu tam olarak bilmiyorum. – Hank