linq-to-entities

The type arguments for method cannot be inferred from usage error

孤人 提交于 2019-12-25 16:55:20
问题 I have a generic method for paging which I am trying to invoke. But I am getting a compile time error: The type arguments for method cannot be inferred from usage Method: public static IQueryable<T> OrderedPagedResults<T, TResult, TType>(IQueryable<T> query, int pageNum, int pageSize, Expression<Func<T, TResult>> orderByProperty, bool isAscendingOrder, out int rowsCount, List<KeyValuePair<Expression<Func<T, TType>>, bool>> lstThenByConditions = null) { if (pageSize <= 0) pageSize = 20;

DataGrid itemsSource from Joined Tables in SQL Database using LINQ

折月煮酒 提交于 2019-12-25 11:05:40
问题 i have these tables in my SQL Server Express database. my aim is to join " UserInfo " table with " RelCU " table and display the result in a wpf DataGrid . i tried these codes but got an error while running the project. IQueryable<RelCU> Query = from u in dbEntities.UserInfoes join m in dbEntities.RelCUs on u.UserID equals m.UserID into temp from j in temp.DefaultIfEmpty() select j; DataGridRegisteredUsers.ItemsSource = Query; XAML: <DataGrid x:Name="DataGridRegisteredUsers" IsReadOnly="True"

WCF Data Services join query

时间秒杀一切 提交于 2019-12-25 06:57:19
问题 I want to retrieve the results of this query (Northwind Database): var ent = new Entities(); var query = from c in ent.Customers join o in ent.Orders on c.CustomerID equals o.CustomerID join od in ent.Order_Details on o.OrderID equals od.OrderID join p in ent.Products on od.ProductID equals p.ProductID where p.ProductName == "Chai" select c; by using WCF Data Services. I type this (which doesn't work): http://localhost:29792/WcfDataService1.svc/Customers?$select=CompanyName&$expand=Orders

Linq to Entities query non primitive type

寵の児 提交于 2019-12-25 05:13:06
问题 I have this method I wrote as: private void GetReceivedInvoiceTasks(User user, List<Task> tasks) { var taskList = from i in _db.Invoices join a in user.Areas on i.AreaId equals a.AreaId where i.Status == InvoiceStatuses.Received select i; } Basically I was trying to get all the Invoices in the database in the user's area that have a status of received. I don't understand LINQ too well right now. I'm getting the error: base {System.SystemException} = {"Unable to create a constant value of type

Using pre-existing iqueryable to filter another iqueryable on Entity Framework

有些话、适合烂在心里 提交于 2019-12-25 03:55:32
问题 I have a many to many relationship (Sites, Categories, CategoriesXSite), I need to get all categories filtering by certain site names so I did my homework and made this linq: var filteredcategories = from c in context.Categories from s in c.Sites where s.Name.Contains(siteWord) select c; it works perfectly, the thing is I already have a method that filters sites and I want to reuse it like this: var filteredcategories = from c in context.Categories where c. Sites == FilterSites(siteWord)

access attributes from two entities

試著忘記壹切 提交于 2019-12-25 03:48:10
问题 I created two entities and they have navigation properties. var list = from u in storeDB.Users join a in storeDB.Accounts on u.Id equals a.Id select new { u, a }; if I do a foreach( user in list){ <span>user.Name, user.Money</span> } It does not work. My question is how can I display the content from the result attributes of both tables, that is, of the join?? Users: has Name, Id Accounts: has Id, Money 回答1: I suspect you are using this in an MVC view so you need to create a view model for

Linq to Entities query with array of WHERE conditions

旧城冷巷雨未停 提交于 2019-12-25 03:35:40
问题 How can I create an efficient Linq-to-Entities query when I have an array of parameters in a WHERE clause with OR condition? The array length can be anything. For example: from employees -> return all employees that have EmployeeID of 1, 2 or 3. Stupid way of doing this would be: For index = 0 To employeeArray.Lenght-1 FindID = employeeArray(index) Dim query = From emp In _context.Employees Where emp.EmployeeID = FindID Select emp Next How can I achieve this effectively? 回答1: Dim query = From

Linq adding new rows to table when there is a relation table

我的梦境 提交于 2019-12-25 03:34:55
问题 this question is in relation to my previous question: Linq2Entity Getting Values from reference Table Now i have the problem that i want to add a new entry in Table B. I tried something like this: ObjectQuery<A> aTable = dbConnection.A; ObjectQuery<B> bTable = dbConnection.B; var data = from d in aTable //Reference dataset in Table A where d.ID == myID select d; B bData = new B() { ID = GetNewID(), Text = text, A = data.First() }; dbConnection.AddToB(bData); but this "A = d.First()" does now

Extend the Where method for IQueryable [duplicate]

萝らか妹 提交于 2019-12-25 03:22:51
问题 This question already has an answer here : extend Where for IQueryable (1 answer) Closed 5 years ago . I want to extend the Where to something like this: .WhereEqual("Field", "SomeString") wich must be equivalent to .Where(p => p.Field== "SomeString") , here is my code: public static IQueryable<T> WhereEqual<T>(this IQueryable<T> q, string Field, string Value) { var param = Expression.Parameter(typeof(T), "p"); var prop = Expression.Property(param, Field); var val = Expression.Constant(Value)

Use Linq To Entities subquery within Select clause to fetch a field value

爱⌒轻易说出口 提交于 2019-12-25 03:12:49
问题 Can I use a Linq To Entities subquery within a (linq to entities) Select clause to fetch a filed value like this: var a = someIQueryable; var b = IQueryable_2.Select((a,i)=> new Model { SomeFiled = someIQueryable.Where(w=>w.AA==a.AA).Select(w=>w.Calls).First() }).ToList(); I am getting "Cannot translate method into store expression". Is there any way to do this ? 回答1: I think the issue is caused by Select method (though you could probably provide more details). I'm not sure why you use Select