objectquery

Repository / IQueryable / Query Object

喜欢而已 提交于 2020-01-10 07:22:13
问题 I am building a repository and I've seen in many places 2 reasons not to expose IQueryable outside the repository. 1) The first is because different LINQ providers could behave differently, and this difference should be contained within the repository. 2) The second is to prevent service level developers from modifying the database query such that it accidentally causes performance issues. I guess issue 2 can only be prevented by keeping all query logic within the repository and not allowing

How do I avoid a circular reference while serializing Entity Framework class

我怕爱的太早我们不能终老 提交于 2019-12-23 02:58:06
问题 I have an MVC-3 (RC1) application using Entity Framework 4. I wish to return a JSON object from a controller action. This object is referenced by other objects, which obviously return the reference. I thus receive the following circular reference error: Server Error in '/' Application. A circular reference was detected while serializing an object of type 'Application.Models.ReferenceObject'. Description: An unhandled exception occurred during the execution of the current web request. Please

What is the Equivalent of ObjectQuery.Parameters in DbQuery

醉酒当歌 提交于 2019-12-13 19:09:31
问题 I have code that gets a query using a linq statement making it a DbQuery and not ObjectQuery and I was adding parameters through a foreach loop using that query. But DbQuery has no parameter support. I know I could add them manually. But I have 36 different parameters in my SQL statement. So I need to find a way to add the parameters. foreach (var parameter in query.Parameters) { parameters.Add(new System.Data.SqlClient.SqlParameter { ParameterName = parameter.Name, Value = parameter.Value })

Server-side execution of Entity Framework Query combined with Stored Procedure

旧城冷巷雨未停 提交于 2019-12-12 10:21:54
问题 Is it possible to call a StoredProcedure from an ObjectQuery? Basically I want to dynamically build a query and execute it server-side. You can imagine each query to be part of a search where you can combine different criteria with "and" or "or". It is working fine with ObjectQueries created like this. var query1 = from a in objectContext.Articles where a.Name = 'SOMETHING' select new ResultType { ArticleId = a.ArticleId, Name = a.Name }; var query2 = from a in objectContext.Articles where a

How do I avoid a circular reference while serializing Entity Framework class

那年仲夏 提交于 2019-12-07 13:28:25
I have an MVC-3 (RC1) application using Entity Framework 4. I wish to return a JSON object from a controller action. This object is referenced by other objects, which obviously return the reference. I thus receive the following circular reference error: Server Error in '/' Application. A circular reference was detected while serializing an object of type 'Application.Models.ReferenceObject'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Repository / IQueryable / Query Object

∥☆過路亽.° 提交于 2019-11-29 22:26:19
I am building a repository and I've seen in many places 2 reasons not to expose IQueryable outside the repository. 1) The first is because different LINQ providers could behave differently, and this difference should be contained within the repository. 2) The second is to prevent service level developers from modifying the database query such that it accidentally causes performance issues. I guess issue 2 can only be prevented by keeping all query logic within the repository and not allowing any form of external query building? But that does seem a bit impractical to me. Issue 1 would seem to

How can i convert a DBQuery<T> to an ObjectQuery<T>?

巧了我就是萌 提交于 2019-11-28 01:50:19
I've got a DBQuery<T> which converts to an IQueryable<T> (this bit works fine). But then I'm trying to convert the IQueryable to an ObjectQuery .. which fails :- public void Foo(this IQueryable<T> source) { // ... snip ... ObjectQuery<T> objectQuery = source as ObjectQuery<T>; if (objectQuery != null) { // ... do stuff ... } } This used to work before I changed over to Entity-Framework 4 CTP5 Magic Unicorn blah blah blah . Now, it's not working - ie. objectQuery is null . Now, DBQuery<T> inherits IQueryable<T> .. so I thought this should work. If i change the code to .. var x = (ObjectQuery<T>

How can i convert a DBQuery<T> to an ObjectQuery<T>?

孤者浪人 提交于 2019-11-26 22:01:29
问题 I've got a DBQuery<T> which converts to an IQueryable<T> (this bit works fine). But then I'm trying to convert the IQueryable to an ObjectQuery .. which fails :- public void Foo(this IQueryable<T> source) { // ... snip ... ObjectQuery<T> objectQuery = source as ObjectQuery<T>; if (objectQuery != null) { // ... do stuff ... } } This used to work before I changed over to Entity-Framework 4 CTP5 Magic Unicorn blah blah blah . Now, it's not working - ie. objectQuery is null . Now, DBQuery<T>