iqueryable

Missing QueryableExtensions in EF 6

人走茶凉 提交于 2019-12-23 11:22:20
问题 I can't call the new QueryableExtensions ( ToListAsync , ForEachAsync ,...) provided with EntityFramework 6. But i can call others ( Include , Intersect ). I've a reference to System.Data.Entity . So apparently, i've an older version of System.Data.Entity , with the latest version of EntityFramework. Is it possible? My code does not compile and I cannot see the ForEachAsync method in the object browser. I'm working with Visual Studio 2013, .Net 4.5, EntityFramework 6.1.3, Wpf. Edit Entity

Converting an IQueryable<T> to a DbSet<T>

坚强是说给别人听的谎言 提交于 2019-12-23 09:08:58
问题 I'm not sure that this is possible, but I'm trying to unit test a repository that uses a DbSet. I thought the easiest solution would just be to make an Enumerable, and replace the DbSet with that, this is my attempt. I'm using C#, EntityFramework, XUnit, and Moq [Fact] public void SomeTest() { //arrange var mockContext = new Mock<MyDbContext>(); var mockData = new List<Person> { new Person { Name = "Jim", Age = 47 } }; mockContext.Setup(db => db.Persons).Returns((DbSet<Person>)mockData

ASP MVC: Should services return IQueryable's?

白昼怎懂夜的黑 提交于 2019-12-23 07:51:29
问题 What do you think? should your DAO return an IQueryable to use it in your controllers? 回答1: At the moment, it sounds attractive, but really isn't. 回答2: No. Your controllers shouldn't be handling any complex logic at all. Keep them slim; the Model (not DAO) should hand the Controller back everything it needs to pass onto the View. Seeing queries (or even queryables) in a Controller class is something I would consider to be a code smell. 回答3: I love passing IQueryable into my controllers

Using EF and WebAPI, how can I return a ViewModel AND support IQueryable/OData? [duplicate]

给你一囗甜甜゛ 提交于 2019-12-23 07:38:57
问题 This question already has answers here : Web API Queryable - how to apply AutoMapper? (4 answers) Closed 6 years ago . I've got an ASP.NET WebAPI project. I've recently created EntityFramework entities for all my data tables. But I don't want to expose my data layer & schema to my users. How can I map my entities to a ViewModel (automapper?) and provide IQueryable return type so that my API supports OData? OData supports query composition and SQL-like parameters. I guess I'd need to provide

C# Select clause returns system exception instead of relevant object

给你一囗甜甜゛ 提交于 2019-12-23 06:57:33
问题 I am trying to use the select clause to pick out an object which matches a specified name field from a database query as follows: objectQuery = from obj in objectList where obj.Equals(objectName) select obj; In the results view of my query, I get: base {System.SystemException} = {"Boolean Equals(System.Object)"} Where I should be expecting something like a Car , Make , or Model Would someone please explain what I am doing wrong here? The method in question can be seen here: // this function

IQueryable to List<T>

别说谁变了你拦得住时间么 提交于 2019-12-23 03:43:12
问题 I know IQueryable yields no result but just an expression builder, my problem is how can actually use it to execute query and return the set as List to be able to bind it on a grid. IQueryable query = _campaignManager.GetCampaign(filter, values); // this line returns error List<Campaign> campaigns = query.Cast<Campaign>().ToList(); grdCampaigns.DataSource = campaigns; grdCampaigns.DataBind(); additional details: GetCampaign() public IQueryable GetCampaign(string filter, params object[] values

Where is EntitySet<T>'s “Results View”?

纵饮孤独 提交于 2019-12-23 03:26:19
问题 When looking at a linked EntitySet<T> of a LINQ to SQL mapped entity, I see the following: I'd like to see the following (achieved by using the .AsQueryable() extension method) so that I can click the little refresh icon and see the content: Why can't I see the Results View on a regular plain EntitySet<T> ? Also, I've noticed that on this MSDN page it says: In LINQ to SQL, the EntitySet<TEntity> class implements the IQueryable interface. From what I can see, EntitySet<TEntity> doesn't inherit

How can you expose a multi-layer model that has derived classes and members for OData services?

南笙酒味 提交于 2019-12-22 18:16:55
问题 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 such

How do you transfer the execution of a Expression created by an IQueryable object to a IEnumerable?

喜欢而已 提交于 2019-12-22 11:01:54
问题 In my code I'd like to make my repositories IQueryable. This way, the criteria for selection will be a linq expression tree. Now if I want to mock my repository in theorie this is very easy : just implement the interface of my repository (which is also a IQueryable object). My mock repository implementation would be only a in memory collection, but my question is : Do you know an easy way to implement the IQueryable interface of my mock, to transfer the query to my in-memory collection

how should I initialize IQueryable variables, before use a Union expression?

给你一囗甜甜゛ 提交于 2019-12-22 05:28:14
问题 I've created an extension method over IQueryable type, which takes a subset of entities and filters them upon some criterrions. My problem is that I can't return a Union expression made of the variables, without all being initialized first. Null values, as aprears, are not valid. public static IQueryable<Person> FilterHairColors(this IQueryable<Person> subQuery, string[] hairColors) { IQueryable<Person> q1 = null; IQueryable<Person> q2 = null; IQueryable<Person> q3 = null; IQueryable<Person>