2015-11-21 8 views
1

Может ли база данных быть создана из библиотеки классов (путем определения & DbContext внутри библиотеки классов) с использованием EF7 в приложениях UWP (Win 10)?Создание базы данных из библиотеки классов с использованием EF7

Я получаю следующее сообщение об ошибке в Package Manager Console, когда я выполнить команду: Add-Migration

PM> Add-Migration CreateDb 
System.InvalidOperationException: The property 'Segments' on entity type 'System.Uri' has not been added to the model or ignored. 
    at Microsoft.Data.Entity.Metadata.Conventions.Internal.PropertyMappingValidationConvention.Apply(InternalModelBuilder modelBuilder) 
    at Microsoft.Data.Entity.Metadata.Conventions.Internal.ConventionDispatcher.OnModelBuilt(InternalModelBuilder modelBuilder) 
    at Microsoft.Data.Entity.Metadata.Internal.InternalModelBuilder.Validate() 
    at Microsoft.Data.Entity.ModelBuilder.Validate() 
    at Microsoft.Data.Entity.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator) 
    at Microsoft.Data.Entity.Infrastructure.ModelSource.<>c__DisplayClass8_0.<GetModel>b__0(Type k) 
    at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) 
    at Microsoft.Data.Entity.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator) 
    at Microsoft.Data.Entity.Internal.DbContextServices.CreateModel() 
    at Microsoft.Data.Entity.Internal.LazyRef`1.get_Value() 
    at Microsoft.Data.Entity.Internal.DbContextServices.get_Model() 
    at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.<>c.<AddEntityFramework>b__0_5(IServiceProvider p) 
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryService.Invoke(ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceProvider.ScopedCallSite.Invoke(ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass12_0.<RealizeService>b__0(ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) 
    at Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetService[T](IServiceProvider provider) 
    at Microsoft.Data.Entity.Design.Internal.DesignTimeServicesBuilder.<>c__DisplayClass7_0.<ConfigureContextServices>b__8(IServiceProvider _) 
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryService.Invoke(ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceProvider.TransientCallSite.Invoke(ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite.Invoke(ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceProvider.TransientCallSite.Invoke(ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass12_0.<RealizeService>b__0(ServiceProvider provider) 
    at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) 
    at Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) 
    at Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetRequiredService[T](IServiceProvider provider) 
    at Microsoft.Data.Entity.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType) 
    at Microsoft.Data.Entity.Design.OperationExecutor.<AddMigrationImpl>d__7.MoveNext() 
    at System.Linq.Buffer`1..ctor(IEnumerable`1 source) 
    at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) 
    at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0() 
    at Microsoft.Data.Entity.Design.OperationExecutor.OperationBase.Execute(Action action) 
The property 'Segments' on entity type 'System.Uri' has not been added to the model or ignored. 

Кто-нибудь пытался создать базу данных из класса-библиотеки с успехом?

+0

Я не проверял, но я не понимаю, почему он не будет работать в библиотеке классов выиграть 10. Он не ожидал, что он будет работать в переносимой библиотеке классов. –

+0

@KenTucker. Я попытался создать базу данных из библиотеки классов в демонстрационном проекте. Я получаю сообщение об ошибке: «Сегменты свойств для типа сущности« System.Uri »не был добавлен в модель или проигнорирован ». как упоминалось в вопросе. – Anil

+0

Какой язык устройства вы тестируете, пожалуйста? – AymenDaoudi

ответ

0

Использование EF из библиотеки шагов:

1. Add `EntityFramework.Sqlite` NuGet package in library 
2. Define Model & ViewModels in library 
3. Add reference to library in startup project 
4. Add `EntityFramework.Commands` NuGet package in startup project 
5. Run `Add-Migration` command in library