iqueryable

Concat Two IQueryables with Anonymous Types?

旧时模样 提交于 2019-12-04 03:21:15
I've been wrestling with this a little while and it's starting to look like it may not be possible. I want to Concat() two IQueryable s and then execute the result as a single query. I tried something like this: var query = from x in ... select new { A = ... B = ... C = ... }; var query2 = from y in ... select new { A = ... B = ... C = ... }; var query3 = query.Concat(query2); However, the last line gives me the following error: 'System.Linq.IQueryable' does not contain a definition for 'Concat' and the best extension method overload 'System.Linq.ParallelEnumerable.Concat(System.Linq

IQueryable Lambda Projection Syntax

跟風遠走 提交于 2019-12-03 14:54:09
I have an IQueryable whose Entity Framework 4 objects I would like to project to their DTO equivalents. One such object 'Person' is an EF4 class, and the corresponding POCO PersonP is a class I've defined. I am using Automapper to map between them. However, when I try the following code: IQueryable<Person> originalModel = _repo.QueryAll(); IQueryable<PersonP> projection = originalModel.Select(e => Mapper.Map<Person, PersonP>(e)); The projection generates this error at runtime: LINQ to Entities does not recognize the method 'TestSite.Models.PersonP Map[Person,PersonP](TestSite.DataLayer.Model

Performing part of a IQueryable query and deferring the rest to Linq for Objects

五迷三道 提交于 2019-12-03 13:10:46
I have a Linq provider that sucessfully goes and gets data from my chosen datasource, but what I would like to do now that I have my filtered resultset, is allow Linq to Objects to process the rest of the Expression tree (for things like Joins, projection etc) My thought was that I could just replace the expression constant that contains my IQueryProvider with the result-sets IEnumerable via an ExpressionVisitor and then return that new expression. Also return the IEnumerable's provider from my IQueryable...but this does not seem to work :-( Any idea's? Edit: Some good answers here, but given

IQueryable C# Select

社会主义新天地 提交于 2019-12-03 12:36:41
this is my code... but i need select only column to display in my Datagridview. I Need the code to select only some columns.. example Select{t => t.usu_Login, t => t.usu_Login} public List<tb_usuario> Get(FilterDefinition filter) { var contexto = new indNET_Entities(); IQueryable<tb_usuario> Consulta = contexto.tb_usuario.AsQueryable<tb_usuario>() .Where(t => t.usu_Ativo == 1) .OrderBy(t => t.usu_Login); return Consulta.ToList(); } If you only want a limited number of columns and you intend to pass the result out of the method, first declare a concrete type to describe the elements. public

Force an IQueryable to execute?

[亡魂溺海] 提交于 2019-12-03 11:35:08
I have a method that 'has no translation to SQL' that I want to perform on an IQueryable, is there a way to force the IQueryable to execute without having to store it in some intermediate class? Is the problem that you want your method to execute locally rather than in the database? If so, AsEnumerable is your friend. It's a very simple method, something like: public IEnumerable<T> AsEnumerable(IEnumerable<T> source) { return source; } The important thing is that it makes the compile-time type of the result IEnumerable<T> rather than IQueryable<T> , which means any LINQ query operators you

How do I mock IQueryable<T>

别等时光非礼了梦想. 提交于 2019-12-03 11:31:51
问题 I am creating a repository that exposes IQueryable. What is the best way to mock this out for my unit testing? Since I am using RhinoMocks for the rest of my mock objects, I tried to do the following: IQueryable<MyObject> QueryObject = MockRepository.GenerateStub<IQueryable<MyObject>>(); This doesn't work though so I tried doing this: IQueryable<MyObject> QueryObject = (new List<MyObject> { new MyObject() }).AsQueryable(); Is there a better way to do this, or have any other mocking frameworks

Cannot implicitly convert type IEnumerable<T> to IQueryable<T>

纵饮孤独 提交于 2019-12-03 11:06:44
问题 Obfuscated Scenario : A person has zero, one or many pets. Using Linq to Sql, the need is to get an IQueryable list of pets for the given personID. Here's the poorly mangled/butchered/obfuscated portion of the ERD: Code: public IQueryable<Pet> GetPersonPets(int personID) { var personPets= from p in Person where p.ID == somePersonID select p.Pets; return personPets; //fail // return (IQueryable<Pet>)personPets //also fail // return personPets.AsQueryable<Pet>() //also fail } Exception Raised:

IEnumerable<T> and IQueryable<T> clarification?

拜拜、爱过 提交于 2019-12-03 08:54:00
问题 After reading this question, I need to clear up some things. IQueryable<Customer> custs = from c in db.Customers where c.City == "<City>" select c; IEnumerable<Customer> custs = from c in db.Customers where c.City == "<City>" select c; Questions: 1) Is it ok to say that: in the first query the SQLServer is running the whole operation including where clause and returning ONLY the relevant rows - while the second one does SELECT * ... and returns all rows into C# and THEN filters ? 2) What

Cannot implicitly convert type 'System.Linq.IQueryable<int>' to 'int?'

感情迁移 提交于 2019-12-03 05:21:08
var cityList = from country in doc.Element("result") .Element("cities") .Descendants("city") select new { Name = country.Element("name").Value, Code = country.Element("code").Value, CountryCode = int.Parse(country .Element("countrycode") .Value) }; foreach(var citee in cityList) { City city = new City(); city.CountryID = from cnt in db.Countries where cnt.DOTWInternalID == citee.CountryCode select cnt.ID; } I'm getting an error on the second query as seen in the title of this post. I tried converting to int to nullable int but nothing worked. Help me, guys. Thanks it will return an iQueryable,

Convert Dataset to IQueryable<T> or IEnumerable<T>

只谈情不闲聊 提交于 2019-12-03 03:31:19
Since there is no Linq to DB2 yet (c'mon IBM!), and I want to deal with IQueryables or IEnumerables in my code, how would I convert a DataTable to an IQueryable? Or an IEnumerable? I have an interface and a class that matches the columns in the datatable... IQueryable<IMyData> GetAS400Data(..parameters..) { DataSet d = GetData(); ... //Some code to convert d to IQueryable<IMyData> } DataTable.Rows does not support .AsQueryable, since MSFT yanked it, so I'm not sure what to do here. table.AsEnumerable()... table.AsEnumerable().AsQueryable()... However, you'd need to write your own translation (