I am constructing my connectionstring the following way
( with appropriate values)
var builder = new SqlConnectionStringBuilder
{
PersistSecurityInfo = false,
InitialCatalog = "mydatabase",
UserID = "myuser",
Password = "mydatabase",
DataSource = "myserver"
};
var connectionString = builder.ConnectionString;
using (var db = Helper.MakeContext(connectionString)) {
var carrier = db.Carriers.FirstOrDefault(); // fails here with error
Console.WriteLine(carrier.Carrier);
}
Helper在另一个项目中
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using ApiForVivtrack3.Entities;
public static class Helper
{
//public string ConnectionString { get; set; }
public static ApiDbContext MakeContext(string connectionString)
{
var db = new ApiDbContext(connectionString);
return db;
}
}
EF 6.2 DbContext设置为
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity;
namespace ApiForVivtrack3.Entities
{
public partial class ApiDbContext : DbContext
{
public ApiDbContext(string efConnectString)
: base(efConnectString)
{
}
// DbSet declarations
The call stack is
Test method UnitTestProject1.UnitTest1.TestMethod1 threw exception:
System.InvalidOperationException: The store type 'decimal(18,4)' could not be found in the SqlServer provider manifest
at System.Data.Entity.Utilities.DbProviderManifestExtensions.GetStoreTypeFromName(DbProviderManifest providerManifest, String name)
at System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration.ConfigureColumn(EdmProperty column, EntityType table, DbProviderManifest providerManifest)
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__DisplayClass4.<Configure>b__3(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, ICollection`1 entitySets, 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.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
at UnitTestProject1.UnitTest1.TestMethod1() in D:\devnet10\SBD.Common\UnitTestProject2\UnitTest1.cs:line 39
我已经对Decimal(18)进行了文本搜索,但是没有出现
答案 0 :(得分:1)
我知道这是OQ。看到没有答案,我将分享我的工作。
对(18,4)进行查找(ctrl F)或错误消息中的值是多少。您很可能会在解决方案的Fluent API部分中找到文本字符串。 就我而言,我将Fluent API代码从CORE应用程序复制到了EF 6应用程序中。内核使用的“ HasColumnType()”与使用“ HasPrecision()”的EF 6不兼容。
将“ HasColumnType(”替换为“ HasPrecision(”),然后再次运行代码...