linq-to-entities

linq to entities query for count and group by with join on 2 tables

I need a linq to entities query/ lambda expression for the following statement. Any help is greatly appreciated SELECT at.Name, Count(a.AssetTypeId) as CountofAssets, at.AssetTypeId FROM AssetTypes at, Assets a WHERE at.AssetClassId = 7 GROUP BY at.Name,at.AssetTypeID ...

How to query an Entity Framework entities container for objects of derived entity classes?

I have a complex inheritance structure in my data model. A majority of classes in my model (which is designed in VS 2010 with a DB generated by it after) are derived from 3 basic classes. And only these 3 classes can be found among the context members. How do I use all the derived classes at all? ...

Linq to entity select items and give id

I have a table example you can see below ID Name Value 3 NameOne ValueOne 7 NameTwo ValueTwo 10 NameThree ValueThree I need to select with Linq to Entity and get results as you can see in example below: ItemID ItemName 1 NameOne 2 NameTwo 3 NameThree ...

Linq to Entity Dynamic where clause

I have Linq to Entity query like you can see below I am using it five times in my code, everything that change is where clause. is it possible to create a method and pass just where values, not to write all code five times. Thank you items = from t1 in _entities.table1 join t2 in _entities.Table2 on t1.column1 ...

3 methods for adding a "Product" through Entity Framework. What's the difference?

Reading this MSDN article titled "Working with ObjectSet (Entity Framework)" It shows two examples on how to add a Product.. one for 3.5 and another for 4.0. http://msdn.microsoft.com/en-us/library/ee473442.aspx Through my lack of knowledge I am possibly completely missing something here, but i never added a Product like this: //I...

Linq, how to delete items in the middle of a query return?

I got a list of objects in the following query. How to delete items in the middle, saying I want to delete item in 2, 5, and 7 position? thanks var archivedPwds = from archivedPwd in db.PasswordArchive where archivedPwd.UserId == userId orderby archivedPwd.DateCha...

Compile error when calling ToList() when accessing many to many with Linq To Entities

I can't figure out what I am doing wrong. I have the following method: public IList<WObject> GetRelationshipMembers(int relId) { var members = from r in _container.ObjectRelationships where r.Id == relId select r.WObjects; return members.ToList<WObject>(); } Thi...

Is the Entity Framework 4 "Unit of Work" pattern the way to go for generic repositories?

I am looking into creating an Entity Framework 4 generic repository for a new ASP.NET MVC project i am working on. I have been looking at various tutorials and they all seem to use the Unit of Work pattern ... From what i have been reading, EF is using this already within the ObjectContext and you are simply extending this to make your ...

LINQ TO SQL, Dynamic query with DATE type fields

Hello, I'm building a query with the LINQ dynamic library so I don't know how many potential parameters will I have and I get an error when trying to query DATE type fields: Operator '>=' incompatible with operand types 'DateTime' and 'String' When I step through the debugger in the Dynamic.cs it shows that the value is of type string...

LINQ Query Help!

Can someone hep me converting the following SQL query into LINQ? select convert(varchar(10),date,110) as 'Date', max(users) as 'Maximum Number of Users', max(transactions) as 'Maximum Number of Transactions' from stats where datepart(Year, Date) = '2010' group by convert(varchar(10),date,110) order by conv...

In linq-to-entities, how to return objects with a filtered list of children?

I have the following model The first step is to select all the ProductionBlock with var blocks = context.ProductionBlocks; How can I combine the ProductionLog that has no end time with the ProductionBlock? I tried to do it using a reverse lookup like var blocks = context .ProductionLogs .Include("FK_ProductionLog_Producti...

How to start with entity framework and service oriented architecture?

At work I need to create a new web application, that will connect to an MySql Database. (So far I only have expercience with Linq-To-Sql classes and MSSQL servers.) My superior tells me to use the entity framework (he probably refers to Linq-To-Entity) and provide everything as a service based architecture. Unfortunately nobody at work ...

asp.net mvc nerddinner question linq to entities join question

Hi experts, I am working on a website similar to nerddinner. Is it possible to perform similar join using Linq to entities what is done with linq to sql in nerddinner. I am posting the codes below. public IQueryable<Dinner> FindByLocation(float latitude, float longitude) { var dinners = from dinner in FindUpcomingDinners() ...

Why does Linq to Entities generate Left Outer Joins?

I was wondering if anyone knew why linq to entities always seems to generate left outer joins. I would understand it on an optional relationship but it doesn't make good sense when the relationship is mandatory. Does anyone have any idea how to make it generate inner joins instead? ...

Total of float column in linq query

I have a linq query, that gets data from a table in a DataContext object. One of the columns in this table has a Datatype of float. I would like to get the total of that specific column. How could I go about doing this? ...

How do I eliminate Error 3002?

Say I have the following table definitions in SQL Server 2008: CREATE TABLE Person (PersonId INT IDENTITY NOT NULL PRIMARY KEY, Name VARCHAR(50) NOT NULL, ManyMoreIrrelevantColumns VARCHAR(MAX) NOT NULL) CREATE TABLE Model (ModelId INT IDENTITY NOT NULL PRIMARY KEY, ModelName VARCHAR(50) NOT NULL, Description VARCHAR(200) NULL) CR...

Entity framework with Linq to Entities performance

If I have a static method like this private static bool TicArticleExists(string supplierIdent) { using (TicDatabaseEntities db = new TicDatabaseEntities()) { if((from a in db.Articles where a.SupplierArticleID.Equals(supplierIdent) select a).Count() > 0) return true; ...

Create LINQ to entities OrderBy expression on the fly

I'm trying to add the orderby expression on the fly. But when the query below is executed I get the following exception: System.NotSupportedException: Unable to create a constant value of type 'Closure type'. Only primitive types ('such as Int32, String, and Guid') are supported in this context. The strange thing is, I am q...

Should repositories expose IQueryable to service layer or perform filtering in the implementation?

I'm trying to decide on the best pattern for data access in my MVC application. Currently, having followed the MVC storefront series, I am using repositories, exposing IQueryable to a service layer, which then applies filters. Initially I have been using LINQtoSQL e.g. public interface IMyRepository { IQueryable<MyClass> GetAll(); } ...

SelectMany in Linq to entity

I was looking at some examples in microsoft site about linq and I see an example that I need to modify! http://msdn.microsoft.com/en-us/vcsharp/aa336758.aspx#SelectManyCompoundfrom3 public void Linq16() { List customers = GetCustomerList(); var orders = from c in customers from o in c.Orders where o.OrderDate >= new Da...