Page 1 of 1

Oracle CodeFirst throws error 'Sequence contains no matching element'

Posted: Thu 31 Jul 2014 09:27
by anand123
I am trying to use codefirst approach with DevArt (Version=8.2.103.6), it throws error as "Sequence contains no matching element"

but it same context works fine for sql server using EF 6.1.

my .Net framework version is 4.5.

stacktrace

Code: Select all

   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   at System.Data.Entity.Utilities.DbProviderManifestExtensions.GetStoreTypeFromName(DbProviderManifest providerManifest, String name)
   at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(EdmProperty column, EntityType table, DbProviderManifest providerManifest, Boolean allowOverride, Boolean fillFromExistingConfiguration)
   at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.<>c__DisplayClass1.<Configure>b__0(Tuple`2 pm)
   at System.Data.Entity.Utilities.IEnumerableExtensions.Each[T](IEnumerable`1 ts, Action`1 action)
   at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.Configure(IEnumerable`1 propertyMappings, DbProviderManifest providerManifest, Boolean allowOverride, Boolean fillFromExistingConfiguration)
   at System.Data.Entity.ModelConfiguration.Configuration.Types.StructuralTypeConfiguration.ConfigurePropertyMappings(IList`1 propertyMappings, DbProviderManifest providerManifest, Boolean allowOverride)
   at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigurePropertyMappings(DbDatabaseMapping databaseMapping, EntityType entityType, DbProviderManifest providerManifest, Boolean allowOverride)
   at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EntityType entityType, DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
   at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
   at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest)
   at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
   at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
   at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
   at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.InternalContext.Initialize()
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at WindowsFormsApplication1.Program.Main() in c:\Users\amichael\Desktop\codefirst\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 23
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
please suggest, how to resolve this.

regards,
Anand

Re: Oracle CodeFirst throws error 'Sequence contains no matching element'

Posted: Thu 31 Jul 2014 12:38
by anand123
error was not specific. need to investigate by each property.

by analyzing found 2 issues initially.

1. In oracle, column names are in upper cases. In sql, it was proper case. fixed using .HasColumn.

2. text type. got same error if typename attribute exists. after commenting, it work in both the databases.

Code: Select all

   //[Column(TypeName = "text")]
        public string DA_COMMENT { get; set; }
I have around 200 tables still :(

please let me if there are any checklist, when we use same context for sql and oracle dbs.

regards,
Anand.

Re: Oracle CodeFirst throws error 'Sequence contains no matching element'

Posted: Tue 05 Aug 2014 14:49
by Shalex
anand123 wrote:In oracle, column names are in upper cases. In sql, it was proper case. fixed using .HasColumn.
This is a designed behaviour: server specific settings (SQL Server) do not work for another server (Oracle) and vice versa.

Solution 1.
You should use database independent mapping in Code-First. For this, try this approach:
a) install Entity Developer Professional Trial for migrating (you can uninstall it after the migration is done, it is needed because it supports System.Data.SqlClient)
b) run your code to create the database objects in SQL Server
c) create the *.edml model (Devart Entity Model) and add all your tables from SQL Server in the model
d) use the DbContext template with the "Database Independent = True" and "Fluent Mapping = True" properties
e) select designer surface and set the Metadata Artifact Processing property of EntityContextModel to Do Not Generate Mapping Files
f) save the model and generate code
g) provide the corresponding connection string to the context in runtime to switch between different database servers.
That's all. Now you can uninstall Entity Developer as a separate tool. dotConnect for Oracle Professional includes its own Entity Developer (it can be used only with Devart.Data.Oracle but it should be enoung for editing the model with database independent approach).

Solution 2.
If you want to stay with Code-First without employing *.edml (DbContext template), we recommend you to switch to using fluent mapping (via modelBuilder). This will allow you to set custom conventions for your mapping: http://blog.devart.com/entity-framework ... #CodeFirst. Additionally, refer to our sample which demonstrates a simultaneous use of several database servers.