linq-to-entities

In linq to entity, how to retrieve objects matching a list of conditions without looping ???

Dear all, I play with a mysql database using ADO entity framework (through devart dot.connect). I get lists of entity objects (a) from listboxs and I would like to make a linq query retrieving all object from a given entity table (b) where there is a b foreign key: //THIS WORKS : IQueryable<Nb_student> nbstud = MainForm.context.Nb_stu...

Performing Left Joins in ADO.NET Entity Framework

Pre .NET 4.0 - the EF does not support the DefaultIfEmpty() clause. Is there a better way of performing a left join on a query? ...

How do LINQ queries against the Entity Framework communicate dates to a SQL Server?

I'm using two LINQ queries to access my database using Entity Framework: The first stores a token in the database and gives it a 60 second timeout: string tokenHash = GetTokenHash(); Token token = new Token() { Client = client, Expiry = DateTime.Now.AddSeconds(60), UserId = userId, TokenHash = tokenHash, }; context.AddT...

Linq to Entities : relationship * - *

Hello, I have on my EF Schema a relationship * - * (designed by a middle table with 2 keys). When I want filter on each (ie : I want all market segment filtered by one function), I execute this query : var requete = from mkt in ent.MARKETSEGMENT_MKT where mkt.FUNCTION2_FUN.Where(fu => fu.FUN_ID == FunId).FirstOrDefault().FUN_ID == Fu...

Linq to Entities Join/Union Statement Help

Trying to learn Linq syntax and am struggling with method-based vs expressions. I have 8 tables that allow users to associate to groups and orgs and have forms associated to groups. To further explain, I assign a form to a group. That group may have a user assigned directly or via an org that the user belongs to. I need a Linq statem...

How to use a JOIN in a LINQ query

I have the following table structure, which is imported into an Entity Framework project: (NOTE: I mislabled T1Name as T2Name in Table1) I have labeled the Entity Objects. The many-to-many joint table Table5, is represented as an EntityCollection<Entity4> in Entity3, and as an EntityCollection<Entity3> in Entity4 (EntityCollection<T>...

How can I return a list of strings from a LINQ to Entities many-many relationship?

I have a view model that needs to encapsulate a couple of many-to-many relationships. I have my LINQ to Entites query that returns the appropriate list, but can't figure out how to return a list of objects. I have a Foo table, and a Bar table. Bar has a FK to Foo.ID, and a Description string. I want to create a FooViewModel that ha...

How to use an Argument in NewExpression as Expression to be used in OrderBy method?

First, I use C# 4.0 and EF 4.0 with POCO object to access database. Next, I create some grid (like jqGrid) for displaying data from database via ASP.NET MVC 2.0. This grid can order data by clicking at the column header. Source code could look like this. // This method will generate data for jqGrid request. // jqGridRequest contain seve...

Converting String to Long ...in LINQ to Entity Framework using a MySQL adaptor.

I have a table with a column of type varchar where the majority of rows have numerical looking values, that is, each string contains nothing but the digits 0 through 9. +------+ | n | +------+ | 123 | | 234 | | BLAH | -- This row is an exception to the rule. | 456 | | 789 | +------+ In MySQL, this works: SELECT * FROM t WHERE n...

using stored procedures as functions from edmx file

hi, i have an entity-model file (edmx) file which contains few tables and few stored procedures. how can i call those stored procedures that are mapped to functions? i thought it should be trivial, and i do see the mapping in the edmx file, but i can't figure how to use it in the code. here is one mapping example: <Function N...

Problem querying with EntityReference

When I execute the code: public List<T> GetCustomerTxList(int customerId) { var matchingPocos = new List<T>(); using (linq.AOMSEntities dataRepos = new linq.AOMSEntities()) { IEnumerable txlist = from t in dataRepos.TransactionRecord ...

crud with telerik radgrid and linq to entity

I was thinking if is it possible to do crud on telerik radgrid and the data were from a linq to entity. I was using edmx, then I have set Radgrid's DataSource with data resulting from a linq query. Here it goes: DatabaseModel.Entities entities = new DatabaseModel.Entities(); RadGrid1.DataSource = from courses in entities.Courses ...

Most popular GroupBy with Linq to Entities

I have a standard store schema with an InvoiceLine table that contains Products. I'd like to get a list of the top 5 products by sales as a List. What's the cleanest way to do that? This can't be the best way: private List<Product> GetTopProducts(int count) { var topProducts = from invoiceLine in storeDB.InvoiceLines ...

Problem with inserting using linq-to-entities

Hi I'm having trouble solving this error. Any help on the problem would be much appreciated, thanks! Error message: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries. Whenever I try to add a Lapt...

Distinct() on Class, anonymus type and SelectListItem

I want to select all categories from a webservice. The webservice does not have a method for that, so I have to get all products, then select all categories that these products are in. When I recieve the data from the webservice, I make WebServiceProduct (ID, Name, etc) and WebServiceCategory (ID, Name, etc) objects of it. This does not...

C# TransactionScope - L2E

Is it worth using System.Transactions.TransactionScope on Linq to Entities? On the MS documentation, it says that SQL calls within ObjectContext.SaveChanges() are all rolled into one transaction internally. We have 1 database connection, that is a local SQLite database on the file system. We just want to make sure all our operations t...

String searching in Linq to Entity Framework

I am wanting to create a Where statement within my Linq statement, but have hit a bit of a stumbling block. I would like to split a string value, and then search using each array item in the Where clause. In my normal Sql statement I would simply loop through the string array, and build up there Where clause then either pass this to a ...

Linq to entities - How to define left join for grouping?

We have two tables - Tasks and TasksUsers (users assigned to task). Task has EntityCollection called TaskUsers. This query returns number of tasks per username: model.TaskCountByAssignee = ( from t in TaskRepository.List() from tu in t.TaskUsers group tu by tu into tug sel...

Get the the most recent and the one before the most recent item

Hi I have a table with many anniversaries : Date + Name. I want to display the next anniversary and the one after with Linq. How can i build the query ? I use EF Thanks John ...

how can i query an already loaded data in EF ?

Hi I have an object Customer with a 1-n relationship to Addresses. I want to be able to take the first address. So i create a method: public Address firstAddress { get { var f=from d in this.Addresses select d; return f; } } I get the following error : Error 5 Impossible to find an i...