compiled-query

Dynamic Order (SQL ORDERBY) in LINQ CompiledQuery

女生的网名这么多〃 提交于 2020-01-01 19:55:34
问题 how can I create a dynamic ORDERBY in my LINQ CompiledQuery (e.g. supply Order Field and Direction as parameters for the compiled query)? 回答1: I think I found it: Check out this link. It will point you to the VS2008 code samples which contains a Dynamic Linq Query Library which contains the extension method below. This will allow you to go: Object.OrderBy("ColumnName"); Here is the extension methods, but you may want the whole library. public static IQueryable<T> OrderBy<T>(this IQueryable<T>

When should I use a CompiledQuery?

↘锁芯ラ 提交于 2019-12-29 03:21:09
问题 I have a table: -- Tag ID | Name ----------- 1 | c# 2 | linq 3 | entity-framework I have a class that will have the following methods: IEnumerable<Tag> GetAll(); IEnumerable<Tag> GetByName(); Should I use a compiled query in this case? static readonly Func<Entities, IEnumerable<Tag>> AllTags = CompiledQuery.Compile<Entities, IEnumerable<Tag>> ( e => e.Tags ); Then my GetByName method would be: IEnumerable<Tag> GetByName(string name) { using (var db = new Entities()) { return AllTags(db).Where

Converting Linq2SQL simple queries to CompiledQueries to increase app performance

风流意气都作罢 提交于 2019-12-23 03:18:15
问题 I am writing a Silverlight for Windows Phone (SDK 7.1) app and I am displaying data from a CompactSQL DB in a LongListSelector control from the Silverlight Toolkit for Windows Phone. Once the list becomes about 150 items long, The app really slows down loading data, navigating to and from pages and animations fail to display (I know using a background thread would help with freeing up the UI thread for animations). I currently have three queries that I use constantly - everytime the data from

Entity Framework 6 Compiled LINQ Query

北战南征 提交于 2019-12-18 05:44:13
问题 I'm trying to improve performance of a web application by caching a query. public static Func<myEntity, List<HASHDuplicates>, IQueryable<FormResponse>> CompiledDuplicatedResponses = CompiledQuery.Compile<myEntity, List<HASHDuplicates>, IQueryable<FormResponse>>( (db, hashes) => from r in db.FormResponse from h in db.IndexHASHes from d in hashes where r.id == h.FormResponseID && h.IndexHASHString == d.hash select r); The error I receive is at compile time: The type 'myEntity' cannot be used as

Why can't you return a List from a Compiled Query?

拟墨画扇 提交于 2019-12-12 18:33:16
问题 I was speeding up my app by using compiled queries for queries which were getting hit over and over. I tried to implement it like this: Function Select(ByVal fk_id As Integer) As List(SomeEntity) Using db As New DataContext() db.ObjectTrackingEnabled = False Return CompiledSelect(db, fk_id) End Using End Function Shared CompiledSelect As Func(Of DataContext, Integer, List(Of SomeEntity)) = _ CompiledQuery.Compile(Function(db As DataContext, fk_id As Integer) _ (From u In db.SomeEntities _

Compiled Query no implicit reference conversion to ObjectContext

廉价感情. 提交于 2019-12-08 18:36:36
问题 I'm creating a delegate to retrieve all album records in the database. I've used this same way in another project, but for some reason I'm getting an error this time. Have I missed a step? I'm not sure why this error is appearing. Code public static readonly Func<CodySolutionEntities, IQueryable<Album>> SelectAlbums = CompiledQuery.Compile<CodySolutionEntities, IQueryable<Album>>( query => from q in query.Albums.Include("Photo") select q); Error Error 1 The type 'CodyData.Diagram

Dynamic Order (SQL ORDERBY) in LINQ CompiledQuery

♀尐吖头ヾ 提交于 2019-12-04 19:19:37
how can I create a dynamic ORDERBY in my LINQ CompiledQuery (e.g. supply Order Field and Direction as parameters for the compiled query)? I think I found it: Check out this link . It will point you to the VS2008 code samples which contains a Dynamic Linq Query Library which contains the extension method below. This will allow you to go: Object.OrderBy("ColumnName"); Here is the extension methods, but you may want the whole library. public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string ordering, params object[] values) { return (IQueryable<T>)OrderBy((IQueryable)source,

Entity Framework 6 Compiled LINQ Query

落爺英雄遲暮 提交于 2019-11-29 09:30:56
I'm trying to improve performance of a web application by caching a query. public static Func<myEntity, List<HASHDuplicates>, IQueryable<FormResponse>> CompiledDuplicatedResponses = CompiledQuery.Compile<myEntity, List<HASHDuplicates>, IQueryable<FormResponse>>( (db, hashes) => from r in db.FormResponse from h in db.IndexHASHes from d in hashes where r.id == h.FormResponseID && h.IndexHASHString == d.hash select r); The error I receive is at compile time: The type 'myEntity' cannot be used as type parameter 'TArg0' in the generic type or method 'System.Data.Entity.Core.Objects.CompiledQuery

When should I use a CompiledQuery?

泄露秘密 提交于 2019-11-28 18:20:58
I have a table: -- Tag ID | Name ----------- 1 | c# 2 | linq 3 | entity-framework I have a class that will have the following methods: IEnumerable<Tag> GetAll(); IEnumerable<Tag> GetByName(); Should I use a compiled query in this case? static readonly Func<Entities, IEnumerable<Tag>> AllTags = CompiledQuery.Compile<Entities, IEnumerable<Tag>> ( e => e.Tags ); Then my GetByName method would be: IEnumerable<Tag> GetByName(string name) { using (var db = new Entities()) { return AllTags(db).Where(t => t.Name.Contains(name)).ToList(); } } Which generates a SELECT ID, Name FROM Tag and execute Where