我该如何解决此错误?

时间:2012-05-26 07:04:22

标签: c# entity-framework

在C#中使用Entity Framework,我收到此错误:

  

条目'AlMizanEntities'已添加。   (d:\文献\ Almizan \ AlMizan \ C#\ AlMizan \ BIN \调试\ AlMizan.vshost.exe.config   第7行

我的代码:

private void Fraz()
{
    label1.Text = "Fraz ...";
    Application.DoEvents();

    AlMizanEntities1 ObjAE = new AlMizanEntities1();
}

public partial class AlMizanEntities1 : ObjectContext
{
   /// <summary>
   /// Initializes a new AlMizanEntities1 object using the connection string found in the 'AlMizanEntities1' section of the application configuration file.
   /// </summary>
   // *ERROR* occurs here
   public AlMizanEntities1() : base("name=AlMizanEntities1", "AlMizanEntities1")
   {
      this.ContextOptions.LazyLoadingEnabled = true;
      OnContextCreated();
   }

   /// <summary>
   /// Initialize a new AlMizanEntities1 object.
   /// </summary>
   public AlMizanEntities1(string connectionString) : base(connectionString, "AlMizanEntities1")
   {
        this.ContextOptions.LazyLoadingEnabled = true;
        OnContextCreated();
   }

   /// <summary>
   /// Initialize a new AlMizanEntities1 object.
   /// </summary>
   public AlMizanEntities1(EntityConnection connection) : base(connection, "AlMizanEntities1")
   {
        this.ContextOptions.LazyLoadingEnabled = true;
        OnContextCreated();
   }
}

1 个答案:

答案 0 :(得分:4)

删除line 7中的D:\Document\Almizan\AlMizan\C#\AlMizan\App.config 或删除该文件中其他位置的重复行。