我有一个非常简单的 Entity Framework 项目与 POCO实体 .我有一个 stored procedure
我使用 EF Wizard
导入的.克尔。
然后我自己做了 EF Entity
然后我 Add Function Import
映射 Stored Procedure
到我的 EF Entity
.
现在......我不知道如何映射我的 EF Entity
到 POCO
.因此,我不断收到以下错误:
Error 11007: Entity type 'XXXXX' is not mapped.
我不确定如何将此实体映射到
POCO
.请问有人可以帮忙吗?
最佳答案
好的。这就是我最终要做的。
使用 POCO
IE。 .edmx
, Custom Tool
被删除/没有自动生成的实体等。
在您的上下文类中...
public class SqlServerContext : ObjectContext, IUnitOfWork
{
public SqlServerContext(EntityConnection entityConnection,
ILoggingService loggingService)
: base(entityConnection) { .... }
public ObjectResult<Location> FindLocationsWithinABoundingBox(decimal upperLeftLongitude,
decimal upperLeftLatitude,
decimal lowerRightLongitude,
decimal lowerRightLatitude)
{
return base.ExecuteFunction<Location>("FindLocationsWithinABoundingBox",
new ObjectParameter("UpperLeftLatitude", upperLeftLongitude),
new ObjectParameter("UpperLeftLongitude", upperLeftLatitude),
new ObjectParameter("LowerRightLongitude", lowerRightLongitude),
new ObjectParameter("LowerRightLatitude", lowerRightLatitude));
}
}
使用自动生成的实体等(设置 EF 的默认方式)
就是这样。
不确定我的 POCO 方式是否是最好的做事方式,但它.. 好.. 工作:)
和 this is a related StackOverflow question I asked关于以服务/IQueryable 方式使用此存储过程... :)
关于.net - 无法在我的 Entity Framework v4 + POCO :( 中使用存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3385372/