Search Results

Search found 436 results on 18 pages for 'iqueryable'.

Page 1/18 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Using an existing IQueryable to create a new dynamic IQueryable

    - by dnoxs
    I have a query as follows: var query = from x in context.Employees where (x.Salary > 0 && x.DeptId == 5) || x.DeptId == 2 order by x.Surname select x; The above is the original query and returns let's say 1000 employee entities. I would now like to use the first query to deconstruct it and recreate a new query that would look like this: var query = from x in context.Employees where ((x.Salary > 0 && x.DeptId == 5) || x.DeptId == 2) && (x,i) i % 10 == 0 order by x.Surname select x.Surname; This query would return 100 surnames. The syntax is probably incorrect, but what I need to do is attach an additional where clause and modify the select to a single field. I've been looking into the ExpressionVisitor but I'm not entirely sure how to create a new query based on an existing query. Any guidance would be appreciated. Thanks you.

    Read the article

  • Chain LINQ IQueryable, and end with Stored Procedure

    - by Alex
    I'm chaining search criteria in my application through IQueryable extension methods, e.g.: public static IQueryable<Fish> AtAge (this IQueryable<Fish> fish, Int32 age) { return fish.Where(f => f.Age == age); } However, I also have a full text search stored procedure: CREATE PROCEDURE [dbo].[Fishes_FullTextSearch] @searchtext nvarchar(4000), @limitcount int AS SELECT Fishes.* FROM Fishes INNER JOIN CONTAINSTABLE(Fishes, *, @searchtext, @limitcount) AS KEY_TBL ON Fishes.Id = KEY_TBL.[KEY] ORDER BY KEY_TBL.[Rank] The stored procedure obviously doesn't return IQueryable, however, is it possible to somehow limit the result set for the stored procedure using IQueryable's? I'm envisioning something like .AtAge(5).AboveWeight(100).Fishes_FulltextSearch("abc"). In this case, the fulltext search should execute on a smaller subset of my Fishes table (narrowed by Age and Weight). Is something like this possible? Sample code?

    Read the article

  • c# syntax and Linq, IQueryable

    - by hdiver
    Hello. This is a question about the SYNTAX of c# and NOT about how we call/use IQueryable Can someone please explain to me: We have this declaration (System.Linq): public static double Average<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, int>> selector) and to call the Average double average = fruits.AsQueryable().Average(s => s.Length); I understand how to call the Average and all the similar static method of IQueryable but I don’t understand the syntax of the declaration. public static double Average<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, int>> selector) What does the <TSource> mean in Average<TSource>( and also the this IQueryable<TSource> source. since only one parameter passes when we call it and the actual lamda expression (s => s.Length); Thanks in advance.

    Read the article

  • Returning IQueryable or Enumerated Object

    - by Tarik
    Hello everyone, I was wondering about the performance difference between these two scenarios and what could the disadvantages be over each other? First scenario : public class Helper //returns IQueryable { public IQueryable<Customer> CurrentCustomer { get{return new DataContext().Where(t=>t.CustomerId == 1); } } public class SomeClass { public void Main() { Console.WriteLine(new Helper().CurrentCustomer.First().Name; } } The second scenario : public class Helper //returns Enumerated result { public Customer CurrentCustomer { get{return new DataContext().First(t=>t.CustomerId == 1); } } public class SomeClass { public void Main() { Console.WriteLine(new Helper().CurrentCustomer.Name; } } Thanks in advance.

    Read the article

  • C# IQueryable<T> does my code make sense?

    - by Pandiya Chendur
    I use this to get a list of materials from my database.... public IQueryable<MaterialsObj> FindAllMaterials() { var materials = from m in db.Materials join Mt in db.MeasurementTypes on m.MeasurementTypeId equals Mt.Id select new MaterialsObj() { Id = Convert.ToInt64(m.Mat_id), Mat_Name = m.Mat_Name, Mes_Name = Mt.Name, }; return materials; } But i have seen in an example that has this, public IQueryable<MaterialsObj> FindAllMaterials() { return from m in db.Materials join Mt in db.MeasurementTypes on m.MeasurementTypeId equals Mt.Id select new MaterialsObj() { Id = Convert.ToInt64(m.Mat_id), Mat_Name = m.Mat_Name, Mes_Name = Mt.Name, }; } Is there a real big difference between the two methods... Assigning my linq query to a variable and returning it... Is it a good/bad practise? Any suggestion which should i use?

    Read the article

  • IQueryable<> from stored procedure (entity framework)

    - by mmcteam
    I want to get IQueryable<> result when executing stored procedure. Here is peace of code that works fine: IQueryable<SomeEntitiy> someEntities; var globbalyFilteredSomeEntities = from se in m_Entities.SomeEntitiy where se.GlobalFilter == 1234 select se; I can use this to apply global filter, and later use result in such way result = globbalyFilteredSomeEntities .OrderByDescending(se => se.CreationDate) .Skip(500) .Take(10); What I want to do - use some stored procedures in global filter. I tried: Add stored procedure to m_Entities, but it returns IEnumerable<> and executes sp immediately: var globbalyFilteredSomeEntities = from se in m_Entities.SomeEntitiyStoredProcedure(1234); Materialize query using EFExtensions library, but it is IEnumerable<>. If I use AsQueryable() and OrderBy(), Skip(), Take() and after that ToList() to execute that query - I get exception that DataReader is open and I need to close it first(can't paste error - it is in russian). var globbalyFilteredSomeEntities = m_Entities.CreateStoreCommand("exec SomeEntitiyStoredProcedure(1234)") .Materialize<SomeEntitiy>(); //.AsQueryable() //.OrderByDescending(se => se.CreationDate) //.Skip(500) //.Take(10) //.ToList(); Also just skipping .AsQueryable() is not helpful - same exception. When I put ToList() query executes, but it is too expensive to execute query without Skip(), Take().

    Read the article

  • How to get IQueryable<> from stored procedure (entity framework)

    - by mmcteam
    I want to get IQueryable<> result when executing stored procedure. Here is peace of code that works fine: IQueryable<SomeEntitiy> someEntities; var globbalyFilteredSomeEntities = from se in m_Entities.SomeEntitiy where se.GlobalFilter == 1234 select se; I can use this to apply global filter, and later use result in such way result = globbalyFilteredSomeEntities .OrderByDescending(se => se.CreationDate) .Skip(500) .Take(10); What I want to do - use some stored procedures in global filter. I tried: Add stored procedure to m_Entities, but it returns IEnumerable<> and executes sp immediately: var globbalyFilteredSomeEntities = from se in m_Entities.SomeEntitiyStoredProcedure(1234); Materialize query using EFExtensions library, but it is IEnumerable<>. If I use AsQueryable() and OrderBy(), Skip(), Take() and after that ToList() to execute that query - I get exception that DataReader is open and I need to close it first(can't paste error - it is in russian). var globbalyFilteredSomeEntities = m_Entities.CreateStoreCommand("exec SomeEntitiyStoredProcedure(1234)") .Materialize<SomeEntitiy>(); //.AsQueryable() //.OrderByDescending(se => se.CreationDate) //.Skip(500) //.Take(10) //.ToList(); Also just skipping .AsQueryable() is not helpful - same exception.

    Read the article

  • C# LINQ: How to remove element from IQueryable<T>

    - by aximili
    How do you loop through IQueryable and remove some elements I don't need. I am looking for something like this var items = MyDataContext.Items.Where(x => x.Container.ID == myContainerId); foreach(Item item in items) { if(IsNotWhatINeed(item)) items.Remove(item); } Is it possible? Thanks in advance

    Read the article

  • LINQ: How to remove element from IQueryable<T>

    - by aximili
    How do you loop through IQueryable and remove some elements I don't need. I am looking for something like this var items = MyDataContext.Items.Where(x => x.Container.ID == myContainerId); foreach(Item item in items) { if(IsNotWhatINeed(item)) items.Remove(item); } Is it possible? Thanks in advance

    Read the article

  • How can I write a clean Repository without exposing IQueryable to the rest of my application?

    - by Simucal
    So, I've read all the Q&A's here on SO regarding the subject of whether or not to expose IQueryable to the rest of your project or not (see here, and here), and I've ultimately decided that I don't want to expose IQueryable to anything but my Model. Because IQueryable is tied to certain persistence implementations I don't like the idea of locking myself into this. Similarly, I'm not sure how good I feel about classes further down the call chain modifying the actual query that aren't in the repository. So, does anyone have any suggestions for how to write a clean and concise Repository without doing this? One problem I see, is my Repository will blow up from a ton of methods for various things I need to filter my query off of. Having a bunch of: IEnumerable GetProductsSinceDate(DateTime date); IEnumberable GetProductsByName(string name); IEnumberable GetProductsByID(int ID); If I was allowing IQueryable to be passed around I could easily have a generic repository that looked like: public interface IRepository<T> where T : class { T GetById(int id); IQueryable<T> GetAll(); void InsertOnSubmit(T entity); void DeleteOnSubmit(T entity); void SubmitChanges(); } However, if you aren't using IQueryable then methods like GetAll() aren't really practical since lazy evaluation won't be taking place down the line. I don't want to return 10,000 records only to use 10 of them later. What is the answer here? In Conery's MVC Storefront he created another layer called the "Service" layer which received IQueryable results from the respository and was responsible for applying various filters. Is this what I should do, or something similar? Have my repository return IQueryable but restrict access to it by hiding it behind a bunch of filter classes like GetProductByName, which will return a concrete type like IList or IEnumerable?

    Read the article

  • Is an IQueryable a query or just an object which can be queried?

    - by Albic
    I'm kinda confused what the IQueryable interface actually represents. The MSDN documentation for IQueryable says: "Provides functionality to evaluate queries against a specific data source." The documentation for IQueryProvider says: "Defines methods to create and execute queries that are described by an IQueryable object." The name and the documentation summary suggest that it is an object/data store which can be queried. The second quote and the fact the ObjectQuery class from the Entity Framework implements IQueryable suggest it is a query which can be executed. Did I misunderstood something or is it really kinda fuzzy?

    Read the article

  • Differences between query using LINQ and IQueryable interface directly?

    - by JohnMetta
    Using Entity Framework 4, and given: ObjectSet<Thing> AllThings = Context.CreateObjectSet<Thing>; public IQueryable<Thing> ByNameA(String name) { IQueryable<Thing> query = from o in AllThings where o.Name == name select o; return query; } public IQueryable<Thing> ByNameB(String name) { return AllThings.Where((o) => o.Name == name); } Both return IQueryable< instances, and thus the query doesn't hit the server until something like ToList() is called, right? Is it purely readability that is the difference, or are the using fundamentally different technologies on the back-end?

    Read the article

  • Time to start returning IQueryable<T> instead of IList<T> to my Web UI / Web API Layer?

    - by JohnnyO
    I've got a multi-layer application that starts with the repository pattern for all data access and it returns IQueryable to the Services layer. The Services layer, which includes all of the business logic, returns IList to the Controllers (note: I'm using ASP.NET MVC for the UI layer). The benefit of returning IQueryable in the data access layer is that it allows my repositories to be extremely simple and the database queries to be deferred. However, I'm triggering the database queries in my services layer so that my unit tests is more reliable and I don't give flexibility to the Controllers to reshape my queries. However, I've recently encountered several situations where deferring the execution of queries down to the Controllers would have been significantly more performant because the Controllers had to do some projections on the data that was UI specific. Additionally, with the emergence of things like oData, I was starting to wonder if end points (e.g. web UI or web apis) should be working directly with IQueryable. What are your thoughts? Is it time to start returning IQueryable from the services layer to the UI layer? Or stick with IList? This thread here: http://stackoverflow.com/questions/718624/to-return-iqueryablet-or-not-return-iqueryablet seems to vouch for returning IList to the UI layers, but I was wondering if things are changing because of new emerging technologies and techniques.

    Read the article

  • Should I return IEnumerable<T> or IQueryable<T> from my DAL?

    - by Gary '-'
    I know this could be opinion, but I'm looking for best practices. As I understand, IQueryable implements IEnumerable, so in my DAL, I currently have method signatures like the following: IEnumerable<Product> GetProducts(); IEnumerable<Product> GetProductsByCategory(int cateogoryId); Product GetProduct(int productId); Should I be using IQueryable here? What are the pros and cons of either approach? Note that I am planning on using the Repository pattern so I will have a class like so: public class ProductRepository { DBDataContext db = new DBDataContext(<!-- connection string -->); public IEnumerable<Product> GetProductsNew(int daysOld) { return db.GetProducts() .Where(p => p.AddedDateTime > DateTime.Now.AddDays(-daysOld )); } } Should I change my IEnumerable<T> to IQueryable<T>? What advantages/disadvantages are there to one or the other?

    Read the article

  • Will my LinqToSql execution be deffered if i filter with IEnumerable<T> instead of IQueryable<T>?

    - by cottsak
    I have been using these common EntityObjectFilters as a "pipes and filters" way to query from a collection a particular item with an ID: public static class EntityObjectFilters { public static T WithID<T>(this IQueryable<T> qry, int ID) where T : IEntityObject { return qry.SingleOrDefault<T>(item => item.ID == ID); } public static T WithID<T>(this IList<T> list, int ID) where T : IEntityObject { return list.SingleOrDefault<T>(item => item.ID == ID); } } ..but i wondered to myself: "can i make this simpler by just creating an extension for all IEnumerable<T> types"? So i came up with this: public static class EntityObjectFilters { public static T WithID<T>(this IEnumerable<T> qry, int ID) where T : IEntityObject { return qry.SingleOrDefault<T>(item => item.ID == ID); } } Now while this appears to yield the same result, i want to know that when applied to IQueryable<T>s will the expression tree be passed to LinqToSql for evaluating as SQL code or will my qry be evaluated in it's entirety first, then iterated with Funcs? I'm suspecting that (as per Richard's answer) the latter will be true which is obviously what i don't want. I want the same result, but the added benefit of the delayed SQL execution for IQueryable<T>s. Can someone confirm for me what will actually happen and provide simple explanation as to how it would work?

    Read the article

  • Linq filtering an IQueryable<T> (System.Data.Linq.DataQuery) object by a List<T> (System.Collection.

    - by Klaptrap
    My IQueryable line is: // find all timesheets for this period - from db so System.Data.Linq.DataQuery var timesheets = _timesheetRepository.FindByPeriod(dte1, dte2); My List line is: // get my team from AD - from active directory so System.Collection.Generic.List var adUsers = _adUserRepository.GetMyTeam(User.Identity.Name); I wish to only show timesheets for those users in the timesheet collection that are present in the user collection. If I use a standard c# expression such as: var teamsheets = from t in timesheets join user in adUsers on t.User1.username equals user.fullname select t; I get the error "An IQueryable that returns a self-referencing Constant expression is not supported" Any recommendations?

    Read the article

  • ASP MVC LINQ to SQL IQueryable Array out of bounds?

    - by Jacob Huggart
    Hey guys, I have an Iqueryable that is populated from the database and then converted to an Array. That works fine. The issue is when I only have 1 element in the Array. I try to use the 0th element and it says "ArrayOutOfBoundsException". When I have 2+ elements in the array and pull elements 0 and 1 it works fine. What gives?

    Read the article

  • get count from Iqueryable<T> in linq-to-sql?

    - by Pandiya Chendur
    The following code doesn't seem to get the correct count..... var materials = consRepository.FindAllMaterials().AsQueryable(); int count = materials.Count(); Is it the way to do it.... Here is my repository which fetches records... public IQueryable<MaterialsObj> FindAllMaterials() { var materials = from m in db.Materials join Mt in db.MeasurementTypes on m.MeasurementTypeId equals Mt.Id where m.Is_Deleted == 0 select new MaterialsObj() { Id = Convert.ToInt64(m.Mat_id), Mat_Name = m.Mat_Name, Mes_Name = Mt.Name, }; return materials; }

    Read the article

  • linq to sql using foreign keys returning iqueryable(of myEntity]

    - by Gern Blandston
    I'm trying to use Linq to SQL to return an IQueryable(of Project) when using foreign key relationships. Using the below schema, I want to be able to pass in a UserId and get all the projects created for the company the user is associated with. DB tables: Projects Projid ProjCreator FK (UserId from UserInfo table) Companyid FK (CompanyID from Companies table) UserInfo UserID PK Companyid FK Companies CompanyId PK Description I can get the iqueryable(of project) when simply getting the ProjectCreator with this: Return (From p In db.Projects _ Where p.ProjectCreator = Me.UserId) But I'm having trouble getting the syntax to get a iqueryable(of projects) when using foreign keys. Below gives me an IQueryable(of anonymous) but I can't seem to convince it to give me an IQueryable(of project) even if I try to cast it: Dim retval = (From p In db.Projects _ Join c In db.Companies On p.CompanyId Equals c.CompanyId _ Join u In db.UserInfos On u.CompanyId Equals c.CompanyId _ Where u.Login = UserId)

    Read the article

  • The performance implications of IEnumerable vs. IQueryable

    It all started innocently enough. I was implementing a "Older Posts/Newer Posts" feature for my new web site and was writing code like this:IEnumerable<Post> FilterByCategory(IEnumerable<Post> posts, string category) {  if( !string.IsNullOrEmpty(category) ) { return posts.Where(p => p.Category.Contains(category)); }}...  var posts = FilterByCategory(db.Posts, category);  int count = posts.Count();... The "db" was an EF object context object, but it could just as...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • The performance implications of IEnumerable vs. IQueryable

    It all started innocently enough. I was implementing a "Older Posts/Newer Posts" feature for my new web site and was writing code like this:IEnumerable<Post> FilterByCategory(IEnumerable<Post> posts, string category) {  if( !string.IsNullOrEmpty(category) ) { return posts.Where(p => p.Category.Contains(category)); }}...  var posts = FilterByCategory(db.Posts, category);  int count = posts.Count();... The "db" was an EF object context object, but it could just as...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

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

    - by Aneef
    Hi this is my code 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; } Im getting an error on the second query as the title of this post, i tried converting to int, to nullable int nothing worked? help me guys Thanks,

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >