linq to 实体存储过程返回事后需要额外的联接
我有一个返回表类型的存储过程。但是,具有存储过程的EF模型仅返回当前表类,而没有关联的类。因此,当我遍历引用的(子/父)表时,这些引用的表值到处都是空值。
我知道这是预期的,因为存储过程仅返回该表(从该表中选择 *),但我现在想在调用存储过程之后创建一个联接子句以访问我的 EF 模型中的其余引用表。
这是我的代码,稍加修改以使其易于理解我需要什么......
var coll = db.SearchContacts(keyword,param1,param2)
//returns Contact types,works great
现在我想做...(虽然我知道语法已关闭)
var ExtColl = coll join db.Address on coll.Address
join db.Department on coll.Department <- something similar
...这样我现在可以有访问该部门 (department.desc), 或此联系人的地址 (address.civic) 信息。
在我已经从数据库中的存储过程收到它之后,我不知道如何实现这种格式的格式。
好吧,这是我正在做的事情的更新......
var ps = from d in db.SearchContacts(param1,param2)
select d.Id;
var p = from e in db.Contacts
.Include("Table1Ref")
.Include("Table2Ref")
.Include("Table3Ref")
Where(BuildOrExpression<DBMOdel.Contact,long>(e=>e.Id,ps.ToList()))
select e;
现在我得到了我想要的回报,除了一件事...... 有一些表格引用了进一步引用的表格 我想添加,并且 Include 不允许 我将它们直接添加到联系人中,因为这些表不是 引用联系人,但另一个表引用联系人 再一层/一层...所以联系人参考地址 并引用省份地址... 我需要访问省份信息(例如描述) 但需要正确完成我的连接语句...
所以我正在考虑使用连接语句,但不知道这种分配或连接的语法... 联系方式->地址在AdressId上,地址-> ProvinceId 上的省
所以我想我的 linq 语句看起来像这样...
var p = from e in db.Contacts
.Include("Table1Ref")
.Include("Table2Ref")
.Include("Table3Ref")
Where(BuildOrExpression<DBMOdel.Contact,long>(e=>e.Id,ps.ToList()))
-> join o in db.Province on o.ProvinceId equals e.Address.ProvinceId
select e;
但没有达到预期的效果...任何人都可以帮忙吗? 我想我可能还会将 linq to sql 或 object 与 linq to entity 混合在一起...... 这是我收到的错误
“调用‘Join’方法的关键选择器类型在底层商店提供程序中不可比较。”
I have a stored procedure that returns the table type. However, the EF model that has the stored procedure, only returns the present table class, but no associated classes. So when I traverse my referenced (child/parent) tables, I get nulls everywhere for those referenced table values.
I know this is expected as the stored procedure returns only that table (select * from that table), but I now would like to create a join clause AFTER calling the store procedure to get access to the rest of the referenced tables in my EF model.
Here is my code , slightly modified to make it easy to understand what I need...
var coll = db.SearchContacts(keyword,param1,param2)
//returns Contact types,works great
...now what I would like to do....(although I know syntax is off)
var ExtColl = coll join db.Address on coll.Address
join db.Department on coll.Department <- something similar
...so that I may now have access to that department (department.desc),
or address (address.civic) info from this contact.
I am at a loss as to how to implement this style of formatting AFTER I have already received it from the stored proc in the db.
Ok, so here is an update of what I am doing...
var ps = from d in db.SearchContacts(param1,param2)
select d.Id;
var p = from e in db.Contacts
.Include("Table1Ref")
.Include("Table2Ref")
.Include("Table3Ref")
Where(BuildOrExpression<DBMOdel.Contact,long>(e=>e.Id,ps.ToList()))
select e;
Now I am getting the return I want except for one thing....
there are tables that reference further referenced tables
that I would like to add, and Include does not allow
me to add them unto Contacts directly as these tables are not
referencing Contact but another table that references Contact
one layer/level further...so contacts references address
and address references province...
and I need to get access to the province info (such as description)
but need to finish my join statement properly....
So I am thinking of using join statement, but do not know the syntax for assigning or joining of this kind...
Contact -> Address on AdressId, Address -> Province on ProvinceId
SO i am thinking my linq statement would look like this...
var p = from e in db.Contacts
.Include("Table1Ref")
.Include("Table2Ref")
.Include("Table3Ref")
Where(BuildOrExpression<DBMOdel.Contact,long>(e=>e.Id,ps.ToList()))
-> join o in db.Province on o.ProvinceId equals e.Address.ProvinceId
select e;
but am not getting the desired effect...can anyone help?
I think I might be also mixing linq to sql or object with linq to entity...
this is the error I am getting for it
"The key selector type for the call to the 'Join' method is not comparable in the underlying store provider."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有将表连接到存储过程的 SQL 语法,因此 EF 也无法执行此操作。
替代方案:
后一种选择可能会表现得更好,但灵活性较差。由你来权衡利弊。
There is no SQL syntax to join tables to stored procedures, so EF won't be able to do this either.
Alternatives:
The latter option is likely to perform (much) better, but is less flexible. It's up to you to weigh the pros and cons.