星期六, 7月 03, 2021

[EF] The entity type is not part of the model for the current context

新增 DContext 時搞烏龍,連線字串內指定 emdx 的 metadata 沒有指定到對的 DbContext,導致執行時就拋出該錯誤訊息
The entity type Type is not part of the model for the current context
[EF] The entity type Type is not part of the model for the current context-1

修正連線字串 edmx metadata 的 csdl、ssdl 和 msl 對應 DbContext 就解決該問題
<connectionStrings>
	<add name="CustomDbContext"
		 connectionString="
			metadata=
				res://*/DbContext.CustomDbContext.csdl| 
				res://*/DbContext.CustomDbContext.ssdl| 
				res://*/DbContext.CustomeDbContext.msl;
				provider=System.Data.SqlClient;
				provider connection string="
				data source=.\SQLInstance;
				initial catalog=DBName;
				User Id=UserID;
				Password=PWD;
				integrated security=False;
				multipleactiveresultsets=True;
				application name=EntityFramework""
		 providerName="System.Data.EntityClient"/>
</connectionStrings>

沒有留言:

張貼留言