iqueryable

Type or namespace name could not be found

I use this: public class ConstructionRepository { private CRDataContext db = new CRDataContext(); public IQueryable<Material> FindAllMaterials() { //return db.Materials; var materials = from m in db.Materials join Mt in db.MeasurementTypes on m.Measureme...

Linq to NHibernate using Queryable.Where predicate

I am querying an SQLite database using LINQ to NHibernate. Person is an entity containing an Id and a Name: public class Person { public Guid Id { get; private set; } public string Name { get; private set; } } Let's say my db table contains a single person whose name is "John". This test works as expected: var query = from ...

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

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...

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

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...

IQueryable<> from stored procedure (entity framework)

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...

Linq based generic alternate to Predicate<T>?

I have an interface called ICatalog as shown below where each ICatalog has a name and a method that will return items based on a Predicate<Item> function. public interface ICatalog { string Name { get; } IEnumerable<Item> GetItems(Predicate<Item> predicate); } A specific implementation of a catalog may be linked to catalogs ...

How do I override the Contains method of IQueryable during a unit test?

So here's the thing: I've got an app that I'm testing that uses LINQ to Entities (EF4/.NET4). The app binds to an implementation of the Contains method that ignores nulls and, due to the way the database is configured, ignores case. That works great. However, when I call into the same methods from my unit tests, I'm passing in a fake co...

How do I add a where filter using the original Linq-to-SQL object in the following scenario

I am performing a select query using the following Linq expression: Table<Tbl_Movement> movements = context.Tbl_Movement; var query = from m in movements select new MovementSummary { Id = m.DocketId, Created = m.DateTimeStamp, CreatedBy = m.Tbl_User.FullName, ...

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

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)...

Extend SubSonic's IQueryable Structure (via LINQ?)

I'm working on a project that groups data by a "customer id". When the user logs in, they're limited to that customer and that customer only. I'm working with SubSonic3, and what I've got looks something like this: public IEnumerable<Models.Foo> FindFoo(int userID, string searchText, int pageIndex, int pageSize) { return from item ...

c# syntax and Linq, IQueryable

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 Aver...

[Linq-To-Sql]How to return two values of different datatypes?

Here is my repository method which returns UserId , public IQueryable<int> getLoginStatus(string emailId, string password) { return (from r in taxidb.Registrations where (r.EmailId == emailId && r.Password == password) select r.UserId); } How to return UserName which is a string along with UserId... Any sugge...

Should repositories expose IQueryable to service layer or perform filtering in the implementation?

I'm trying to decide on the best pattern for data access in my MVC application. Currently, having followed the MVC storefront series, I am using repositories, exposing IQueryable to a service layer, which then applies filters. Initially I have been using LINQtoSQL e.g. public interface IMyRepository { IQueryable<MyClass> GetAll(); } ...

How to dispose data context after usage

Hi fellow programmer I have a member class that returned IQueryable from a data context public static IQueryable<TB_Country> GetCountriesQ() { IQueryable<TB_Country> country; Bn_Master_DataDataContext db = new Bn_Master_DataDataContext(); country = db.TB_Countries .OrderBy(o => o.CountryNam...

Chain LINQ IQueryable, and end with Stored Procedure

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 nva...

how to rotate around each record in linq and show that in view

Hi, I have four tables in my database and i want to join that's and return record's and show that into searchController! My query is this: public IQueryable PerformSearch(string query) { if (!string.IsNullOrEmpty(query)) { var results = from tbl1 in context.Table1 join tbl2 in context.Table2 on tbl...

Using an existing IQueryable to create a new dynamic IQueryable

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...

LINQ: How to remove element from IQueryable<T>

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 ...

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

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 usin...

IQueryable<t> Or IList<t>

Hi , I have some methods in my BLL that fetch some records from database and pass it to UI for binding to Data Controls such as Gridview or ... I could choose my return data type of the methods whether IQueryable<t> or Ilist<t> . My question is which one would be better for me and why ? Actually i don't know the difference between t...