连接字符串故障元数据异常

本文关键字:异常 元数据 故障 字符串 连接 | 更新日期: 2023-09-27 17:59:44

我的项目中有两个模型。当我添加第二个模型时,我在所有账户页面中都出现了这个错误:

System.Data.MetadataException: The specified schema is not valid. Errors:
(8.6): error 0040: the nclob type is not qualified with a namespace or alias. Only primitive types can be used without qualification.
At line 34 of `InitializeSimpleMembershipAttribute.cs` : 
    using (var context = new UsersContext())
Ligne 33 :                     {
Ligne 34 :                         if (!context.Database.Exists())
Ligne 35 :                         {
Ligne 36 :                             // Create the SimpleMembership database without Entity Framework migration schema

以及我的连接字符串:

<connectionStrings>
    <add name="DefaultConnection" connectionString="User Id=devart;Password=1234;Data Source=localhost:1521" providerName="Devart.Data.Oracle" />
    <add name="Entities" connectionString="metadata=res://*/Models.ModelMAE.csdl|res://*/Models.ModelMAE.ssdl|res://*/Models.ModelMAE.msl;provider=Oracle.DataAccess.Client;provider connection string=&quot;DATA SOURCE=localhost:1521;PASSWORD=1234;USER ID=TEST&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

usercontext连接字符串1:

public class UsersContext : DbContext
{
    public UsersContext()
        : base("DefaultConnection")
    {
    }
    public DbSet<UserProfile> UserProfiles { get; set; }
}

UserContext连接字符串2:

public class EntitiesMAE : DbContext
{
    public EntitiesMAE() : base("name=EntitiesMAE")
    {
    }
    public DbSet<OFFRE> OFFRE { get; set; }
    public DbSet<REGION> REGION { get; set; }
}

问题出现在第二个连接字符串entities中,当我删除它时,一切都正常。请问怎么修?

连接字符串故障元数据异常

这似乎与这个问题有关:

http://forums.devart.com/viewtopic.php?t=21488

本文推荐了两种方法。1.禁用约定(我不建议这样做)2.使用OracleEntityProviderConfig配置解决方案。IgnoreSchemaName=true

他们还提到使用了一个特定的DbContext模板,你可以从这篇文章中找到它(我讨厌仅仅发布链接,但那里有太多的信息需要总结):

http://blog.devart.com/entity-developer-ef-code-first-dbcontext-template.html

然而,这是为EF 4.1编写的,你没有说明你使用的是什么版本的EF。。。所以我不确定这些是否仍然适用于你可能使用的任何版本。

因此,要点是不能只替换提供者而不进行其他更改。你将不得不进行一些其他更改,我建议使用类似的代码用DevArt DbContext模板生成代码,看看它产生了什么,然后把代码放在你的应用程序中。

此外,您的代码显然是错误的。您使用的是不存在的连接字符串(您说连接字符串称为实体,但您的代码使用的是名为EntitiesMAE的连接字符串),您还说第二个上下文称为UserContext,但代码称为Entities MAE。我建议清理你的代码,让它有你的真实代码,因为否则我们只是试图帮助你处理无效的代码。