简体   繁体   English

在Entity Framework中使用没有主键的只读表

[英]Working with a Read Only table without a primary key in Entity Framework

Working with a client that has a readonly database and a table that has no primary key. 使用具有只读数据库和没有主键的表的客户端。 I am attempting to compare one table, "item" (has a primary) with "Pics" [No key] in order to get results from "item" that have pictures. 我试图将一个表“ item”(具有主表)与“ Pics” [No key]进行比较,以便从具有图片的“ item”中获取结果。 Whether or not each item has a picture in "Pics". 每个项目是否在“图片”中都有图片。 I cannot edit the databases themselves in SQL. 我无法使用SQL编辑数据库本身。

My ultimate goal is to return the results that only have pictures. 我的最终目标是返回仅包含图片的结果。

I've tried to use a raw SQL Query and then convert it to an IQueryable, however this does not allow me to search items using other parameters and is EXTREMELY slow. 我尝试使用原始SQL查询,然后将其转换为IQueryable,但是这不允许我使用其他参数搜索项目,而且速度非常慢。 (there are probably 75+ columns in the "item" table and 10,000+ total items) I can only figure out how to use the query with 'SELECT *'. (“项目”表中可能有75+列,总共10,000+个项目)我只能弄清楚如何在“ SELECT *”中使用查询。

Controller: 控制器:

entities db = new entities();

var results = (from s in db.items
                           select s);

...

var Pics = db.Database.SqlQuery<Item>(
"SELECT * FROM dbo.Pics
AS p JOIN dbo.item
AS i ON 
i.item = p.item
WHERE p.Pic = 'Yes'").AsQueryable(); 

...

results = Pics;

...

return View(results);

Try this 尝试这个

var results = from i in db.items
              join p in db.Pics
              on i.item equals p.item
              where p.Pic == "Yes"
              select i;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM