Search Results

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

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

  • IQueryable and lazy loading

    - by Nelson
    I'm having a hard time determining the best way to handle this... With Entity Framework (and L2S), LINQ queries return IQueryable. I have read various opinions on whether the DAL/BLL should return IQueryable, IEnumerable or IList. Assuming we go with IList, then the query is run immediately and that control is not passed on to the next layer. This makes it easier to unit test, etc. You lose the ability to refine the query at higher levels, but you could simply create another method that allows you to refine the query and still return IList. And there are many more pros/cons. So far so good. Now comes Entity Framework and lazy loading. I am using POCO objects with proxies in .NET 4/VS 2010. In the presentation layer I do: foreach (Order order in bll.GetOrders()) { foreach (OrderLine orderLine in order.OrderLines) { // Do something } } In this case, GetOrders() returns IList so it executes immediately before returning to the PL. But in the next foreach, you have lazy loading which executes multiple SQL queries as it gets all the OrderLines. So basically, the PL is running SQL queries "on demand" in the wrong layer. Is there any sensible way to avoid this? I could turn lazy loading off, but then what's the point of having this "feature" that everyone was complaining EF1 didn't have? And I'll admit it is very useful in many scenarios. So I see several options: Somehow remove all associations in the entities and add methods to return them. This goes against the default EF behavior/code generation and makes it harder to do some composite (multiple entity) LINQ queries. It seems like a step backwards. I vote no. If we have lazy loading anyway which makes it hard to unit test, then go all the way and return IQueryable. You'll have more control farther up the layers. I still don't think this is a good option because IQueryable ties you to L2S, L2E, or your own full implementation of IQueryable. Lazy loading may run queries "on demand", but doesn't tie you to any specific interface. I vote no. Turn off lazy loading. You'll have to handle your associations manually. This could be with eager loading's .Include(). I vote yes in some specific cases. Keep IList and lazy loading. I vote yes in many cases, only due to the troubles with the others. Any other options or suggestions? I haven't found an option that really convinces me.

    Read the article

  • How to dispose data context after usage

    - by Erwin
    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.CountryName); return country; } As you can see I don't delete the data context after usage. Because if I delete it, the code that call this method cannot use the IQueryable (perhaps because of deferred execution?). How to force immediate execution to this method? So I can dispose the data context.. Thank you :D

    Read the article

  • If I select from an IQueryable then the Include is lost

    - by Connor Murphy
    The include does not work after I perform a select on the IQueryable query. Is there a way arround this? My query is public IQueryable<Network> GetAllNetworks() { var query = (from n in _db.NetworkSet .Include("NetworkContacts.Contact") .Include("NetworkContacts.Contact.RelationshipSource.Target") .Include("NetworkContacts.Contact.RelationshipSource.Source") select (n)); return query;; } I then try to populate mya ViewModel in my WebUI layer using the following code var projectedNetworks = from n in GetAllNetworks() select new NetworkViewModel { Name = n.Name, Contacts = from contact in networkList .SelectMany(nc => nc.NetworkContacts) .Where(nc => nc.Member == true) .Where(nc => nc.NetworkId == n.ID) .Select(c => c.Contact) select contact, }; return projectedNetworks; The problem now occurs in my newly createdNetworkViewModel The Contacts object does include any loaded data for RelationshipSource.Target or RelationshipSource.Source The data should is there when run from the original Repository IQueryable object. However the related include data does not seem to get transferred into the new Contacts collection that is created from this IQueryable using the Select New {} code above. Is there a way to preserve this Include data when it gets passed into a new object?

    Read the article

  • Stored Procedure or calculations via IQueryable?

    - by Shawn Mclean
    This is a question that is based on choosing performance over design practices. If I have a method that will be executed many times a second; public static IQueryable<IPerson> InRadius(this IQueryable<IPerson> query, Coordinate center, double radius) { return (from u in query where CallHeavyMathFormula(u, center, radius) select u); } This extension method for IQueryable generates a SQL that does some heavy maths calculation (Cosine, Sine, etc). This would mean the application sends 1-2KB of sql to the server per call. I've heard of placing all application logic, in your application. I also would like to change to a database such as azure or one of those scalable databases in the future. How do I handle something like this? Should I leave it as it is now or write stored procedures? How do applications like twitter or facebook do it?

    Read the article

  • OData EndPoint/DataService Using IEnumerable<IQueryable>

    - by Elijah Glover
    I am using NHibernate with NHibernate.Linq, and have a bunch of dynamically loading modules each with their own POCO's and Mappings (ClassMap<POCO). I have created OData services before, but normally with a datacontext and IQueryable as Properties/Getters. What I want is to create the service by passing in IEnumerable, into the constructor IEnumerable<IQueryable>> queryableObjects; var dataService = new DataService(queryableObjects); Is this at all possible?

    Read the article

  • Is it possible to mimic IQueryable with NHibernate?

    - by George
    Is it possible to mimic IQueryable with NHibernate? I was looking at Nhibernate docs and for what i could tell, it always returns a List of objects, that have it's attributes indexed by a integer. Ok, perfect, that works. But is there a way to retrieve objects like LINQ? With something like IQueryable? Thanks

    Read the article

  • NHibernate IQueryable Collection as Property of Root

    - by Khalid Abuhakmeh
    Hello and thank you for taking the time to read this. I have a root object that has a property that is a collection. For example : I have a Shelf object that has Books. // now public class Shelf { public ICollection<Book> Books {get; set;} } // want public class Shelf { public IQueryable<Book> Books {get;set;} } What I want to accomplish is to return a collection that is IQueryable so that I can run paging and filtering off of the collection directly from the the parent. var shelf = shelfRepository.Get(1); var filtered = from book in shelf.Books where book.Name == "The Great Gatsby" select book; I want to have that query executed specifically by NHibernate and not a get all to load a whole collection and then parse it in memory (which is what currently happens when I use ICollection). The reasoning behind this is that my collection could be huge, tens of thousands of records, and a get all query could bash my database. I would like to do this implicitly so that when NHibernate sees and IQueryable on my class it knows what to do. I have looked at NHibernates Linq provider and currently I am making the decision to take large collections and split them into their own repository so that I can make explicit calls for filtering and paging. Linq To SQL offers something similar to what I'm talking about.

    Read the article

  • Dynamically Run IQueryable Method

    - by Micah
    Hi! I'm trying to run the Count() function of a Linq statement in an overriden Gridview function. Basically, I want to be able to assign a linq query to a gridview, and on the OnDataBound(e) event in my new extended gridview have it retrieve the count, using the IQueryable. This is where I'm at so far: protected override void OnDataBound(EventArgs e) { IEnumerable _data = null; if (this.DataSource is IQueryable) { _data = (IQueryable)this.DataSource; } System.Type dataSourceType = _data.GetType(); System.Type dataItemType = typeof(object); if (dataSourceType.HasElementType) { dataItemType = dataSourceType.GetElementType(); } else if (dataSourceType.IsGenericType) { dataItemType = dataSourceType.GetGenericArguments()[0]; } else if (_data is IEnumerable) { IEnumerator dataEnumerator = _data.GetEnumerator(); if (dataEnumerator.MoveNext() && dataEnumerator.Current != null) { dataItemType = dataEnumerator.Current.GetType(); } } Object o = Activator.CreateInstance(dataItemType); object[] objArray = new object[] { o }; RowCount = (int)dataSourceType.GetMethod("Count").Invoke(_data, objArray); Any ideas? I'm really new with working with IQueryables and Linq so I may be way off. How can I get my _data to allow me to run the Count function?

    Read the article

  • Translate an IQueryable instance to LINQ syntax in a string

    - by James Dunne
    I would like to find out if anyone has existing work surrounding formatting an IQueryable instance back into a LINQ C# syntax inside a string. It'd be a nice-to-have feature for an internal LINQ-to-SQL auditing framework I'm building. Once my framework gets the IQueryable instance from a data repository method, I'd like to output something like: This LINQ query: from ce in db.EiClassEnrollment join c in db.EiCourse on ce.CourseID equals c.CourseID join cl in db.EiClass on ce.ClassID equals cl.ClassID join t in db.EiTerm on ce.TermID equals t.TermID join st in db.EiStaff on cl.Instructor equals st.StaffID where (ce.StudentID == studentID) && (ce.TermID == termID) && (cl.Campus == campusID) select new { ce, cl, t, c, st }; Generates the following LINQ-to-SQL query: DECLARE @p0 int; DECLARE @p1 int; DECLARE @p2 int; SET @p0 = 777; SET @p1 = 778; SET @p2 = 779; SELECT [t0].[ClassEnrollmentID], ..., [t4].[Name] FROM [dbo].[ei_ClassEnrollment] AS [t0] INNER JOIN [dbo].[ei_Course] AS [t1] ON [t0].[CourseID] = [t1].[CourseID] INNER JOIN [dbo].[ei_Class] AS [t2] ON [t0].[ClassID] = [t2].[ClassID] INNER JOIN [dbo].[ei_Term] AS [t3] ON [t0].[TermID] = [t3].[TermID] INNER JOIN [dbo].[ei_Staff] AS [t4] ON [t2].[Instructor] = [t4].[StaffID] WHERE ([t0].[StudentID] = @p0) AND ([t0].[TermID] = @p1) AND ([t2].[Campus] = @p2) I already have the SQL output working as you can see. I just need to find a way to get the IQueryable to translate into a string representing its original LINQ syntax (with an acceptable translation loss). I'm not afraid of writing it myself, but I'd like to see if anyone else has done this first.

    Read the article

  • IQueryable<T> Extension Method not working

    - by Micah
    How can i make an extension method that will work like this public static class Extensions<T> { public static IQueryable<T> Sort(this IQueryable<T> query, string sortField, SortDirection direction) { // System.Type dataSourceType = query.GetType(); //System.Type dataItemType = typeof(object); //if (dataSourceType.HasElementType) //{ // dataItemType = dataSourceType.GetElementType(); //} //else if (dataSourceType.IsGenericType) //{ // dataItemType = dataSourceType.GetGenericArguments()[0]; //} //var fieldType = dataItemType.GetProperty(sortField); if (direction == SortDirection.Ascending) return query.OrderBy(s => s.GetType().GetProperty(sortField)); return query.OrderByDescending(s => s.GetType().GetProperty(sortField)); } } Currently that says "Extension methods must be defined in a non-generic static class". How do i do this?

    Read the article

  • SubSonic IQueryable To String Array

    - by Daniel Draper
    Hey All, I have decided to use SubSonic (v3.0) for the first time and thoroughly enjoy it so far however I seem to have stumbled and I am hoping there is a nice neat solution. I have a users, roles and joining table. SubSonic (ActiveRecord) generated an entity User for my users table. A property of User is UserRoles and is of the type IQueryable this is my joining table. I want to convert the IQueryable column name RoleName to a string array. I have only just started playing with Linq as well and know of ToArray() but seem to be missing something or this isn't the function I want. I could iterate over each item in the UserRoles property but seems a little excessive. I appreciate your help! Cheers.

    Read the article

  • Returning IEnumerable<T> vs IQueryable<T>

    - by stackoverflowuser
    what is the difference between returning iqueryable vs ienumerable. 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; Will both be deferred execution? When should one be preferred over the other?

    Read the article

  • IQueryable Where fails to work

    - by Steve
    I am using N-Hibernate and have a class/table called Boxers I also have a prospect table which tells use if the boxer is a prospect. (this table is one column of just the boxersID) So i Want to get all boxers that are prospects (meaning all boxers that have there id in the prospects table) Public static IQueryable<Boxer> IsProspect(this IQueryable<Boxer> query) { return query.Where(x => x.Prospect != null); } this doesnt trim down my list of boxers to the boxers that are prospect... yet if i debug and look at any boxer it will have True or false next to each one correctly... Why isnt the where clause correctly trimming down the list?

    Read the article

  • Cannot .Count() on IQueryable (NHibernate)

    - by Bruno Reis
    Hello, I'm with an irritating problem. It might be something stupid, but I couldn't find out. I'm using Linq to NHibernate, and I would like to count how many items are there in a repository. Here is a very simplified definition of my repository, with the code that matters: public class Repository { private ISession session; /* ... */ public virtual IQueryable<Product> GetAll() { return session.Linq<Product>(); } } All the relevant code in the end of the question. Then, to count the items on my repository, I do something like: var total = productRepository.GetAll().Count(); The problem is that total is 0. Always. However there are items in the repository. Furthermore, I can .Get(id) any of them. My NHibernate log shows that the following query was executed: SELECT count(*) as y0_ FROM [Product] this_ WHERE not (1=1) That must be that "WHERE not (1=1)" clause the cause of this problem. What can I do to be able .Count() the items in my repository? Thanks! EDIT: Actually the repository.GetAll() code is a little bit different... and that might change something! It is actually a generic repository for Entities. Some of the entities implement also the ILogicalDeletable interface (it contains a single bool property "IsDeleted"). Just before the "return" inside the GetAll() method I check if if the Entity I'm querying implements ILogicalDeletable. public interface IRepository<TEntity, TId> where TEntity : Entity<TEntity, TId> { IQueryable<TEntity> GetAll(); ... } public abstract class Repository<TEntity, TId> : IRepository<TEntity, TId> where TEntity : Entity<TEntity, TId> { public virtual IQueryable<TEntity> GetAll() { if (typeof (ILogicalDeletable).IsAssignableFrom(typeof (TEntity))) { return session.Linq<TEntity>() .Where(x => (x as ILogicalDeletable).IsDeleted == false); } else { return session.Linq<TEntity>(); } } } public interface ILogicalDeletable { bool IsDeleted {get; set;} } public Product : Entity<Product, int>, ILogicalDeletable { ... } public IProductRepository : IRepository<Product, int> {} public ProductRepository : Repository<Product, int>, IProductRepository {} Edit 2: actually the .GetAll() is always returning an empty result-set for entities that implement the ILogicalDeletable interface (ie, it ALWAYS add a WHERE NOT (1=1) clause. I think Linq to NHibernate does not like the typecast.

    Read the article

  • IQueryable<> dynamic ordering/filtering with GetValue fails

    - by MyNameIsJob
    I'm attempting to filter results from a database using Entity Framework CTP5. Here is my current method. IQueryable<Form> Forms = DataContext.CreateFormContext().Forms; foreach(string header in Headers) { Forms = Forms.Where(f => f.GetType() .GetProperty(header) .GetValue(f, null) .ToString() .IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) >= 0); } However, I found that GetValue doesn't work using Entity Framework. It does when the type if IEnumerable< but not IQueryable< Is there an alternative I can use to produce the same effect?

    Read the article

  • Dynamic "WHERE IN" on IQueryable (linq to SQL)

    - by user320235
    I have a LINQ to SQL query returning rows from a table into an IQueryable object. IQueryable<MyClass> items = from table in DBContext.MyTable select new MyClass { ID = table.ID, Col1 = table.Col1, Col2 = table.Col2 } I then want to perform a SQL "WHERE ... IN ...." query on the results. This works fine using the following. (return results with id's ID1 ID2 or ID3) sQuery = "ID1,ID2,ID3"; string[] aSearch = sQuery.Split(','); items = items.Where(i => aSearch.Contains(i.ID)); What I would like to be able to do, is perform the same operation, but not have to specify the i.ID part. So if I have the string of the field name I want to apply the "WHERE IN" clause to, how can I use this in the .Contains() method?

    Read the article

  • iqueryable select/where not working

    - by Steve
    I have two tables Boxer and Prospect. Boxers has general stuff like name and and dob etc and a BoxerId While Prospect contains only one value (at the moment) which is a boxerId. If a boxer is a prospect(up and coming boxer) there Id will be in the prospect table. This works fine but now I want to select all boxers that are prospects public static IQueryable<Boxer> IsProspect(this IQueryable<Boxer> query) { //this does not filter down to only prospects!!! return query.Where(x => x.Prospect != null); } This is the function I call using: var repository = GetRepository<Boxer>(); var boxers = repository.Query().IsProspect(); I would hope this would filter my collection of all boxers down to just boxers that are prospects! Oddly it doesnt filter it but if i hover over my boxers object and look at each boxer during debugging I can see "IsProspect" true or false correctly

    Read the article

  • Search a List inside another with IQueryable

    - by ovini poornima
    public static IQueryable<Institution> WithFunds(this IQueryable<Institution> query, IEnumerable<Fund> allowedFunds) { return query. } I want to get the query to return all Institutions having any of the Fund given in 'allowedFunds' list in Institution.Funds. Please help. My class hierarchy goes like this. public partial class Institution { public int Id { get; set; } public virtual ICollection<Fund> Funds { get; set; } } public partial class Fund { public int Id { get; set; } public virtual Institution Institution { get; set; } }

    Read the article

  • Convert to list after Cast<T>

    - by Timmie Sarjanen
    Hi, I need to convert an IQueryable to List(is it possible to convert to IList?). There had not been an problem if it was not that i need to Cast because I have interfaces to my objects. I've tried most things but for some reason I must run Cast first and then ToList() which generates System.NullReferenceException. How do I solve this? public IQueryable GetPhrases() { return (from r in _repository.All<Phrase>() select r).Cast<IPhrase() }

    Read the article

  • How to create anonymous objects of type IQueryable using LINQ

    - by Soham Dasgupta
    Hi, I'm working in an ASP.NET MVC project where I have created a two LinqToSQL classes. I have also created a repository class for the models and I've implemented some methods like LIST, ADD, SAVE in that class which serves the controller with data. Now in one of the repository classes I have pulled some data with LINQ joins like this. private HerculesCompanyDataContext Company = new HerculesCompanyDataContext(); private HerculesMainDataContext MasterData = new HerculesMainDataContext(); public IQueryable TRFLIST() { var info = from trfTable in Company.TRFs join exusrTable in MasterData.ex_users on trfTable.P_ID equals exusrTable.EXUSER select new { trfTable.REQ_NO, trfTable.REQ_DATE, exusrTable.USER_NAME, exusrTable.USER_LNAME, trfTable.FROM_DT, trfTable.TO_DT, trfTable.DESTN, trfTable.TRAIN, trfTable.CAR, trfTable.AIRPLANE, trfTable.TAXI, trfTable.TPURPOSE, trfTable.STAT, trfTable.ROUTING }; return info; } Now when I call this method from my controller I'm unable to get a list. What I want to know is without creating a custom data model class how can I return an object of anonymous type like IQueryable. And because this does not belong to any one data model how can refer to this list in the view.

    Read the article

  • How can I combine a LINQ query with an IQueryable<Guid>

    - by John
    I have a LINQ query that uses 1 table + a large number of views. I'd like to be able to write something like this: IQueryable<Guid> mostViewedWriters; switch (datePicker) { case DatePicker.Last12Hours: mostViewedWriters = from x in context.tempMostViewed12Hours select x.GuidId; break; case DatePicker.Last24Hours: mostViewedWriters = from x in context.tempMostViewed12Hours select x.GuidId; break; case DatePicker.Last36Hours: mostViewedWriters = from x in context.tempMostViewed12Hours select x.GuidId; break; } var query = from x1 in context.Articles join x2 in context.Authors on x1.AuthorId == x2.AuthorId join x3 in mostViewedWriters on x2.AuthorId == x3.Id select new { x2.AuthorName, x1.ArticleId, x1.ArticleTitle }; The above C# is pseudo-code written to protect the innocent (me). The gist of the question is this: I have a query that is related to the results of a view. That view, however, could be one of many different views. All the views return the same data type. I thought that I might be able to create an IQueryable that would contain the Ids that I need and use that query. Alas, that effort has stalled.

    Read the article

  • What is the big deal with IQueryable?

    - by jjr2527
    I've seen a lot of people talking about IQueryable and I haven't quite picked up on what all the buzz is about. I always work with generic List's and find they are very rich in the way you can "query" them and work with them, even run LINQ queries against them. So I'm wondering if there is a good reason to start considering a different default collection in my projects.

    Read the article

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