Good,
The last time I posted this (last week), I did not describe the problem correctly. I created a sample of this problem. Querying local collections works fine if you use it as part of a basic query. The problem I find is its use with part of the subquery. For example.
It's pretty hard to describe without giving you guys a database or code diagram, but I will try my best. I am trying to execute my code with a single request in db. I do not want to tear it up and send some commands. This has some advantages, including avoiding a possible problem, which I will explain to the end of this.
I join some tables that are related. Of course, an attribute table (DataEventAttributes) describes attributes that are unique to a specific row in the main table (DataEvents).
When I request it without any local collection, everything works fine and very fast against my 20 gigabyte database. However, if I put the local set of values in the part of the subquery that receives the results, I get "Queries with local collections are not supported"
It was quite difficult for me to reproduce in my code, so I will comment on it, and I can also make sure that you can follow what I do.
var initialQuery = from dataEvent in DataEvent.GetByQueryExpression(context)
join attribute in DataEventAttribute.GetByQueryExpression(context) on dataEvent.DataEventID
equals attribute.DataEventID
select new
{
ID = dataEvent.DataEventID,
PluginID = dataEvent.DataOwnerID,
TimeStamp = dataEvent.DataTimeStamp,
DataEventKeyID = attribute.DataEventKeyID,
ValueString = attribute.ValueString,
ValueDecimal = attribute.ValueDecimal
};
var someSetOfIDs = new List<int>() {1, 2, 3, 4, 5};
initialQuery = initialQuery.Where(x => x.DataEventKeyID == 1 && someSetOfIDs.Contains((int) x.ValueDecimal));
var attributeBaseQuery = from attribute in DataEventAttribute.GetByQueryExpression(context) select attribute;
var finalQuery = from dataEvent in DataEvent.GetByQueryExpression(context)
where initialQuery.GroupBy(x => x).Select(x => x.Key).Select(x => x.ID).Contains(dataEvent.DataEventID)
select new
{
BasicData =
attributeBaseQuery.Where(
attrValue =>
attrValue.DataEventID == dataEvent.DataEventID &&
attrValue.DataEventKeyID == (short) DataEventTypesEnum.BasicData).FirstOrDefault().
ValueString
};
var finalResult = finalQuery.Take(100).ToList();
, , - .ToList() .Select(x = > x.ID) finalQuery, . -, . sql finalQuery. (show stopper) - , .ToList(), SQL- - , Google , ( , 10-100 ).
, , , , , , , . SQL- , .
, , , - , , , , .
, ?
, .