2

私が見つけたすべてのチュートリアルに従って、簡単なプログラムを実行しようとしています。これは私のテストコードです:

Program.cs:

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EF5WithMySQLCodeFirst
{
    class Program
    {
        static void Main(string[] args)
        {
            using(var context = new DatabaseContext())
            {
                var defaultForum = new Forum { ForumId = 1, Name = "Default", Description="Default forum to test insertion." };
                context.Forums.Add(defaultForum);
                context.SaveChanges();
            }
            Console.ReadKey();
        }

        public class Forum
        {
            public int ForumId { get; set; }
            public string Name { get; set; }
            public string Description { get; set; }
        }

        public class DatabaseContext : DbContext
        {
            public DbSet<Forum> Forums { get; set; }
        }
    }
}

これは web.config です。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" 
             type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
             requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" 
                      sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

using(var context = new DatabaseContext()) 行でコードを実行すると、次のエラーが発生します。

タイプ「EF5WithMySQLCodeFirst.Program+Forum」はマップされませんでした。Ignore メソッドまたは NotMappedAttribute データ注釈を使用して、型が明示的に除外されていないことを確認してください。型がクラスとして定義されていること、プリミティブ、ネスト、またはジェネリックではないこと、および EntityObject から継承されていないことを確認してください。

まだ MySQL に接続しようとはしていませんが、localdb で動作するようにするため、MySQL という名前は無視してください。私は周りを検索しましたが、まだ問題の解決策を得ることができません。

4

1 に答える 1