problem about iqueryable-Collection of common programming errors
Daniel Hilgarth
c# linq entity-framework casting iqueryable
We are trying to cast an instance of IQueryable<EntityObject> to an IQueryable<SpecificEntityObject>, the SpecificEntityObject type is only known at runtime.We have tried using the code below, which does not compile because The type or namespace ‘objType’ does not exist.var t = query.ElementType; Type objType = typeof(IQueryable<>).MakeGenericType(t); var typed = query.Cast<IEnumerable<objType>>();var grouped = typed.GroupByMany(groupBy.Select(grp => grp.Expressi
Joao Leme
c# linq dynamics-crm-2011 automapper iqueryable
Why am I getting: The method ‘Where’ cannot follow the method ‘Select’ or is notsupported. Try writing the query in terms of supported methods or callthe ‘AsEnumerable’ or ‘ToList’ method before calling unsupportedmethods….when using the WHERE clause, like when calling:XrmServiceContext.CreateQuery<Contact>().Project().To<Person>().Where(p => p.FirstName == “John”).First();?This works:XrmServiceContext.CreateQuery<Contact>().Project().To<Person>().First();Also this w
Tim Skauge
c# linq-to-sql iqueryable
Bumped into a strange situation here. Trying to extract cars from a sql database within a certain range of a position (lat/long) and return an IQueryable to do additional logic on the resultset afterwards.public IQueryable<Car> QueryAllCarsByDistance(float latitude, float longitude, int distance) {var cars = from car in QueryAllCars()join i in sqlContext.QueryContactsByDistance(latitude, longitude, distance)on car.ContactId equals i.Idorderby i.Distanceselect car;return cars; }QueryContact
abatishchev
c# linq linq-to-sql ienumerable iqueryable
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?
RemotecUk
linq-to-sql datacontext iqueryable
Ive got the following code which I hacked together from website examples. It works nicely but I dont really understand how it works…public static Func<EuvaTransientDataContext, string, string, int, IQueryable<SecurityAudit>>MatchedIPAddressesAuditRecords =CompiledQuery.Compile((EuvaTransientDataContext db, string username, string ipAddress, int withinHours) =>(from sa in db.SecurityAuditswhere sa.IPAddress == ipAddress &&sa.Username != username &&sa.AuditDateTime
TravisWhidden
c# .net linq linq-to-sql iqueryable
I have a paging API that returns rows a user requests, but only so many at one time, not the entire collection. The API works as designed, but I do have to calculate the total number of records that are available (for proper page calculations). Within the API, I use Linq2Sql and I work a lot with the IQueryable before i finally make my requests. When I go to get the count, I call something like: totalRecordCount = queryable.Count(); The resulting SQL is interesting none the less, but it
peplamb
c# silverlight datetime date iqueryable
I am in a situation where i need to convert fields with DateTime to a Date (DateTime (2011-01-01 00:00:00 ) to Date ( 2011-01-01 just a string with no time )) before i assign the source to the DataGrid ( without using Binding/Converters ) the collection is an IQueryable but not sure how to do it.Let me repeat I want the collection to be manipulated even before its assigned to DataGrid Sourcecan someone help me? Thanks
YuriyP
c# linq-to-sql expression expression-trees iqueryable
I want to create my custom expression for IQueryable. Sample extension method:public static IQueryable<T> GetByIntTest<T>(this IQueryable<T> qSource, Expression<Func<T, int?>> field, int? value) {if (value == null)return qSource;ConstantExpression constantExpression = Expression.Constant(value, typeof(int?));BinaryExpression binaryExpression = Expression.Equal(field.Body, constantExpression);var predicate = Expression.Lambda<Func<T, bool>>(binaryExpressi
Joshua Frank
.net clr iqueryable devart
I asked the question this way because I can imagine that there’s a potentially easy but Devart specific solution, but maybe also a very general solution for any similar situation.I’m using Devart LINQ To Oracle, and generally you create a class like ItemX in the lqml file at design time and specify what table is behind it. Then, at run time, you use a Table(Of ItemX) to query the database. So far so good.Now I’ve got a situation where I have two identical tables, ItemX and ItemY, and I need to
John Saunders
c# reflection iqueryable
I have an IList of Type Entity.I have a string representing the Type of a class derived from Entity.I need to cast my IList to IQueryable of the Type derived from Entity using the string.Sadly, the assembly for Entity and derived classes is not the executing assembly.
semytech
c# multilingual iqueryable
I’m developing a multilingual news portal website using asp.net and c#. Currently the site supports two languages and it will be extended to other additional languages when required. So it is my job to create the basic framework for the site. Based on the client requirements,the content to be stored in the database for the website for the different languages may be different. So, I have created different tables to store the News in different languages (like tblNews_EN, tblNews_am, etc) to store
Mike C
.net vb.net reflection iqueryable linq-expressions
I am trying to select a column from an IEnumerable collection that has a type known only to me at runtime. The only way I can think of using this is using LINQ expressions to build a dynamic call to Queryable.Select. However, I’m having a lot of trouble figuring out the proper syntax to accomplish this.An example of how I would do this in the happy-go-lucky world of knowing everything I need at compile time, my code would look like this:’ Create an IEnumerable(Of String) Dim strings = { “one”,
Shahin
c# linq reflection iqueryable
I need to be able to get something similar to the following to work:Type type = ??? // something decided at runtime with .GetType or typeof; object[] entityList = context.Resources.OfType<type>().ToList();Is this possible? I am able to use .NET 4 if anything new in that allows this.
Robert P.
c# entity-framework lambda iqueryable
I do a query with an IQeryable on an Entity.DbSet. When i insert this line of code: query = query.Where(x => x.VersionInt == query.Max(y => y.VersionInt))The whole IIS breaks down when i compile and run with this line. If i remove it everthing is allright. What’s happening?
user2224821
entity-framework iqueryable dbset iqueryprovider
Im trying to build a wrapper IOrderedQueryable<T> on top of the DBSet<T>, to process any Expression before it is executed agains the internal DB provider. So ive built a sample IOrderedQueryable and an IQueryProvider to intercept the Execute.public class WrapperQueryable<T> : IOrderedQueryable<T> {private readonly IQueryable<T> internalQuery;public WrapperQueryable(IQueryable<T> query){this.internalQuery = query;this.Expression = query.Expression;this.ElementT
zam6ak
entity-framework linq-to-entities iqueryable skip-take
I am trying to build an extension method that will Paginated a query. But in order to avoid exception: System.NotSupportedException was unhandled by user codeMessage=The method ‘Skip’ is only supported for sorted input in LINQ to Entities. The method ‘OrderBy’ must be called before the method ‘Skip’.I’d like to check if OrderBy was applied and if not just return the query… Something like this:public static IQueryable<T> Paginate<T>(this IQueryable<T> query, int page, int page
Ramesh Durai
c# count windows-runtime iqueryable
In WinRT when I call the count method in Queryable class for the IOrderedEnumerable instance it will throw the exception. DoWork(emp); //Working fine DoWork(emp.OrderBy(objects => objects.EmployeeId)); //throw exception..public void DoWork(IEnumerable<object> collection) {var queryable = collection.AsQueryable();int count = 0;if (queryable != null)count = queryable.Count();elsethrow new InvalidOperationException(“Not able to get count”);//Some other operations using queryable… }Excep
Boris
ef-code-first full-text-search iqueryable createquery
I am using .NET 4.5 and EF 5 with Code First approach and now I need to implement Full Text Search. I have already read a lot about it and so far my conclusions are:Stored procedures nor Table Value Functions can not be mapped with Code First. Still I can call them using dynamic sqldbContext.Database.SqlQuery<Movie>(Sql, parameters)But this returns IEnumerable and I want IQueryable so that I can do more filtering before fetching the data from db server. I know I can send those parameters t
MaVRoSCy
c# .net dynamic expression iqueryable
Possible Duplicate:Dynamic LINQ OrderBy I’m trying to create a dynamic sorting to Iqueryable. So bellow you can see that I am following some examples I see here in stackoverflow.var query = dalSession.Query<T>();var res = (from x in query orderby Extensions.Sort<T>(query, “FirstName”) select x).Skip((paging.CurrentPageRecord)).Take(paging.PageSize);public static class Extensions {public static IQueryable<T> Sort<T>(this IQueryable<T> query,string sortField){return
Dave Clemmer
c# wcf-data-services odata iqueryable
I’m trying to expose a model to be available for OData services. The approach I’m currently taking is along the lines of:1) Defining a class in the model to expose IQueryable collections such as:public class MyEntities {public IQueryable<Customer> Customers{get{return DataManager.GetCustomers().AsQueryable<Customer>();}}public IQueryable<User> Users{get{return DataManager.GetUsers().AsQueryable<User>();}} }2) Set up a WCF DataService with the queryable collection class s
tilak
windows-phone-7 sql-server-ce iqueryable isolatedstorage
I need to get the maximum value from table that should belongs to particular category. My code as follows : private int getHighScores(int _playMode){int maxScore = 0;using (HangmanScoreDataContext hangmanDB = new HangmanScoreDataContext(@”isostore:/HangmanScoreDB.sdf”)){IQueryable<TbleHangmanScore> sqlQuery = hangmanDB._tbleHangman;sqlQuery = sqlQuery.Where(p => p.playMode == _playMode); maxScore = sqlQuery.AsQueryable().Max(p => p.score);}return maxScore;}I am gettin
Daniel Cotter
asp.net-mvc linq json telerik iqueryable
Forgive me if this has been asked before; I couldn’t find anything close after a few searches:I’m trying to write an ActionFilter in MVC that will “intercept” an IQueryable and nullify all the parent-child relationships at runtime. I’m doing this because Linq does not serialize objects properly if they have parent-child relationships (it throws a circular reference error because the parent refers to the child, which refers back to the parent and so on), and I need the object serialized to Json f
Web site is in building