实体框架中存储过程的自我跟踪实体 [英] Self-Tracking Entities with Stored Procedure in Entity Framework

查看:67
本文介绍了实体框架中存储过程的自我跟踪实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dears,


技术
===============
我必须使用的技术是WCF和存储程序和实体框架读取数据,而不是插入,更新和删除

任务
= =============== 用户可以直接创建新类别并输入一些新的子类别作为以及。

数据库
===============
类别

分类ID INT
CategoryName VARCHAR(50)
}

子类别
{子SubcategoryID INT
子类别代码VARCHAR(20)
子类别名称VARCAAR( 50)


类别1< ---> N子类别

存储过程
===============
中GetAllCategories()返回[类别]实体

因为我想将这些实体从数据库中分离出来但是具有用于N层应用的自我跟踪功能。
我想做如下所示的事项


实施班级
================
使用(InventoryEntities context = new InventoryEntities)
{
Category [] categoryList = context.GetAllCategories()。ToArray();


由于GetAllCategory()的返回类型是ObjectResult< Category>,因此我不能使用include。而不是ObjectSet< Category>
我想在相同的查询中检索具有子类别的类别,主要点是使用存储过程。

这是一个非常简单的场景,但我必须处理这种情况在我离得更远之前成功了。

如果我想返回一个自我跟踪实体(通过WCF和N-Tiers架构进行更新),并带有以下信息所需技术,我该怎么办?

类别ID类别名称子类别ID子类别名称
1硬件
1服务器
2个笔记本
3显示器
2软件
4许可证
3其他
5服务

是否有人可以给我一个建议如何实现我的目的?
一千万谢谢!!!!

解决方案

据我所知,实体框架还不支持使用存储过程下拉对象图,但是如果在模型中公开外键,则为y你可以获得你的参考文件的存根。然后,您可以在服务器中手动加载这些存根。当然,这可能是一项昂贵的操作。

当然,您也可以将存储过程映射到专用的复杂类型,但是您需要自己进行更改跟踪。

Dears,


Technologies
===============
Technologies that I must use is WCF and Stored Procedures and Entity Framework to read data out, not for insert, update and delete


Tasks
===============
Create a combo box with Category, when users change the selection on the combo box, a list of relative subcategories will be shown on a grid.
User is able to create a new category directly and input some new subcategories as well.


Databases
===============
Category
{
    CategoryID        INT
    CategoryName   VARCHAR(50)
}

SubCategory
{
    SubCategoryID        INT
    SubCategoryCode    VARCHAR(20)
    SubCategoryName   VARCAAR(50)
}

Category   1 <---> N   SubCategory


Stored Procedures
===============
GetAllCategories()  returns  [Category] Entity

Since I want to make those entities seperated from the DB but with Self Tracking functionalities for N-Tier application.
I want to do something like shown as the following


Implementation Class
================
using (InventoryEntities context = new InventoryEntities)
{
      Category[]  categoryList = context.GetAllCategories().ToArray();
}

As this time, I can't use include since the return type for GetAllCategory() is a ObjectResult<Category> rather than ObjectSet<Category>
I want to retrieve category with its subcategories at the same queries and the main point is using stored procedure.

This is a very simple scenario but I must deal with this situation successfully before I move further away.

If I want to return a self-tracking entities (For update purpose through WCF and N-Tiers architecture) with the following information
with the specified technologies required, what can I do?

Category ID      Category Name     SubCategory ID     SubCategory Name
     1                     Hardware
                                                             1                       Server
                                                             2                     Notebook
                                                             3                       Monitor  
    2                      Software
                                                             4                       License
    3                       Others
                                                             5                      Service

Could anyone gives me a suggestion how can I achieve my purpose?

10 millions Thanks !!!!

解决方案

As far as I know, the entity framework does not yet support using stored procedures to pull down object graphs, although if you expose the foreign keys in your model, you can get stubs for your references. You can then load these stubs manually in the server. A potentially expensive operation, of course.

You can also, of course, always map your stored procedure to a dedicated complex type, but then you'll need to do change tracking on your own.


这篇关于实体框架中存储过程的自我跟踪实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆