linq-to-entities

How to programmatically set label text - Linq To Entities

Hello all. I have to set the label text of a load of differnet labels on a web page based upon user preferences. I have the following code that is place upon the label load event (probably wrong!) string memberid = Session["MemberID"].ToString(); string locationid = Session["LocationID"].ToString(); string user...

How can I share entity models from different design surfaces in ADO.NET Entities/LINQ-to-Entities?

In my current project, I am using LINQ-to-SQL with a number of entities defined in separate design surfaces, such as: Questions Events Notes In other design surfaces, I have other entities which can be related to any of the entities above (using a dual foreign key, such as a model type id and the model id itself): Vote Favorite T...

Calling user defined functions in Entity Framework 4

I have a user defined function in a SQL Server 2005 database which returns a bit. I would like to call this function via the Entity Framework. I have been searching around and haven't had much luck. In LINQ to SQL this was obscenely easy, I would just add the function to the Data context Model, and I could call it like this. bool resul...

How to create a very dynamic LinqToEntity query?

I need to build a very dynamic Linq query over a varying number of tables. For example, I have the related tables: Table_A - ID - Name - Desc Table_B - ID - Table_A_ID - Name - Desc Table_C - ID - Table_B_ID - Name - Desc I have a dictionary with information about the table dependencies containing:   tableName, parentTable...

How to manually load an entity as well as a related entity

Hello Everyone, I have two entity objects one that holds billing address information(TBLADDRESS) and one that holds my account addresses(TBLMYACCOUNTADDRESS). At a point in my project i need to load the TBLADDRESS object with the corresponding values from TBLMYACCOUNTADDRESS. Both of which have a relation to LKSTATE. My problem is i c...

Creating reusable Linq queries

I have a select query which is used over and over with different where filters: var query = from row in context.Table select row; How can I save this into a static class variable so I can reuse it in different methods? Like: var results1 = query.Where(condition1); ... var results2 = query.Where(condition2); ...

Linq2EF return type of child class in query projection

If I have entities that inherit from a base entity (say "Widgets", "Gadgets", and "Gizmos" inherit from "Device") and I want to query Devices and return the specific type of each item in the resulting projection, like so: from d in Devices select new { Name = d.Name, Type = d.GetType() }; Which would return a list like: Spring,...

Entity Framework: Different ObjectContext object error with LINQ to Entities assignment

I keep getting the following InvalidOperationException: The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects. when trying to do the following code: newCorr.ReqCode = (from req in context.ReqCodeSet where req.Code.Equals(requirement.Code) ...

Linq2EF: Concat all values in another table into a string

Let's say I have two entities: Physician Credentials And a physician can have many credentials, such as Dr. Jones can have MD, DO, MPH as credentials. So I need to generate a report via Linq that concatenates the credentials into a single string. For example: from p in Physicians select { p.Name p.Credentials (??? <- concatenat...

How do I query a VARCHAR as an integer

Hello, I have a column that holds VARCHARs and I have a flag that determines if the value is a string or integer. I would like perform a search on the integers but they are stored as VARCHAR. How do I do this? I am trying to do this in a where clause. var q = from x in context.table where x.Criteria > 0 select new ...

retrieve Mysql server time using ADO.net

I am using ADO.net and LINQ-to-Entities in VS2010 to connect to Mysql server, and I would like to know what is the current date and time on the server side. Is there any method to do this using a LINQ query? I don't want to use any SQL statements in my program. ...

Get distinct records using linq to entity

Hi I'm using linq to entity in my application. I need to get distinct records based on one column value "Name" So I have a table similar like you can see below: (User) ID Name Country DateCreated I need to select all this items but uniques based on Name (unique). Is it possible to accomplish using linq, if so please show me how. va...

How to use a parameters value as the property to be selected in a LINQ Query ?

Hi All, I am using LINQ-to-Entities and here is my query public void SomeFunction(string searchField) { var data = from a in dx.SomeTable where a.SomeProperty="270" select a; . . . } Now if I had to use the value of the parameter "searchField" as the property to be selected in the where claus...

Why is this working as left join?

Hello, I know this query is working as left join. But more importantly i want to know why is it working as Left Join? How does the query execution flows? var query = from cust in objNorthwindEntities.Customers join orders in objNorthwindEntities.Orders on cust equals orders.Customer into...

LINQ to Entities does not recognize the method

LINQ to Entities does not recognize the method 'Boolean Contains(Int32)' method, and this method cannot be translated into a store expression. var warranty_yes = from i in devicesEntities.device where i.WarrantyDate >= DateTime.Now select i.Id; var warranty_yes_list = warranty_yes.ToList(); var view_query = from i ...

Ordering sub-items within ordered items in a Linq to Entities Query

Hi, I have a few tables, Listings, ListingImages and a few others related to Listings. ListingImages is related to Listings so that you can have many ListingImages per Listing. When I query this table I do; IQueryable<Listing> ListingToSendToView = (from x in DBEntities.ListingSet.Include("ListingImages") ...

EF4/Linq Eager Loading with Include fails to populate all results

Hi, I'm trying out EF4 as part of a .Net 4.0 WCF service. The aim of the service is to return document data as an array of entity objects to any of our ASP.Net apps. The apps are still in .Net 2.0. Due to the nature of the solution I've disabled LazyLoading at context level. I started with this: var revQuery = from revs in context.t...

Using Linq, Trying to Use OrderBy on Object's Children

Hi All, Trying to use Linq with some Entity objects to do a crafty query here. Hoping for some help with a point I'm having a hard time finding decent documentation on: Basically, I'm trying to use OrderBy to order against the child of an object I'm querying against. The difficult part is that the object has multiple children, and base...

Only parameterless constructors and initializers are supported in LINQ to Entities

I have this error in this linq expression : var naleznosci = (from nalTmp in db.Naleznosci where nalTmp.idDziecko == idDziec select new Payments ( nalTmp.Dziecko.Imie, nalTmp.Dziec...

Flexiable update in Linq To Sql

Using Linq To Sql/Entities we have enough flexibility to write select queries But what about update queries. What if i need to do something simple like that: UPDATE suppliers SET supplier_name = (SELECT customers.name FROM customers WHERE customers.customer_id = suppliers.supplier_id) Using Linq to Sql i need to run a lot o...