Tag: linq

Empty response when using DbGeography distance and Entity Framework

I know for a fact that my database contains a post with these two properties: latitude: 44.611589 longitude: -122.215347 I am writing a method to find all posts in the database that are within 50.0 meters of that location. (So, in this case, since there is a post with these exact coordinates, it will have […]

Linq to Entities & SQL Server 2012: Insert consecutive number by a combination of fields

I’m using: Linq to entities and SQL Server 2012. I need to insert consecutive numbers into a table. The numbers need to be consecutive for a combination of other fields in the table. This is the (simplified) table structure: Id: uniqueidentifier ShiftId: uniqueidentifier (NULL) Number: bigint <– This should be consecutive per shift or consecutive […]

Entity Framework Ignore Duplicate Primary Key Values while inserting Multiple Rows at once

I am using LINQ along with Entity-Framework to insert some data in a SQL Server 2012 Database. My Database Table in which the data is being inserted has a primary key and i am inserting about 1000 Records at once. That is i retrieve data in a set of 1000 rows and save those 1000 […]

Duplicate rows in linq query

I’ve got view vw_AllNomenLost in my database SELECT TOP (100) PERCENT ProducerName, NomenCode, SUM(ErrorCount) AS ErrorCount FROM dbo.NomenLost GROUP BY ProducerName, NomenCode ORDER BY ErrorCount DESC and I added it to Entity Model. I want to get top 10 rows by Producer and sorted by ErrorCount db.vw_AllNomenLost.Where(a => a.ProducerName == producer).OrderByDescending(a => a.ErrorCount).Take(10); In the […]

Linq to SQL Delete/Add Child objects

I have a customer table which has a child table called customer addresses. Customer: CustomerID Name IsActive CustomerAddresses: CustomerAddressID CustomerID Street City State ZipCode I would like to update the customer table with a list of customer addresses and have it automatically remove/add the entries if they already exist. Does linq to SQL do this […]

Entity framework join with a subquery via linq syntax

I’m trying to translate a sql query in linq sintax, but I’m having big trouble This is my query in SQL select * FROM dbo.ITEM item inner join ( select SUM([QTA_PRIMARY]) QtaTotale, TRADE_NUM, ORDER_NUM, ITEM_NUM from [dbo].[LOTTI] where FLAG_ATTIVO=1 group by [TRADE_NUM],[ORDER_NUM],[ITEM_NUM] ) TotQtaLottiGroupByToi on item.TRADE_NUM = TotQtaLottiGroupByToi.TRADE_NUM and item.ORDER_NUM = TotQtaLottiGroupByToi.ORDER_NUM and item.ITEM_NUM = […]

I want to display records of current date in order of pending, solved, cancel

I have records like this: empid title complaint_description complain_date status 1 jjn kkjjj 3/march/14 Solved 2 jjkjn jnkjnj 18/mar/14 pending 3 kjjk jkhjk 21/mar/14 Cancel 4 jkjh jhkj 22/mar/14 Solved 5 jkjj jkhjk 22/mar/14 pending 6 nkjn nkjnk 22/marc/14 pending 7 nkjn jnk 22/marc/14 cancel I want the Linq query to display all complaints of […]

LINQ Join Tables from Different Database or DataaContext

var possibleTPMs = (from ui in db1.Users from org in db2.Orgs.Where(o => o.OrgId == ui.OrgId && !o.DeletedFlag).DefaultIfEmpty() where !ui.DeletedFlag && ui.ActiveFlag && ui.OrgId == 1 && ui.UserId != 1 select new { ui.UserId, ui.LastName, ui.FirstName }).ToList(); Above is sample LINQ but having an errors, How can I join these two tables that came from two […]

linq to entities simple query gives “object reference not set to an instance of an object”

Using sql server 2012 and visual studio 2012 c# .net 4.0 I have a working system, that runs a daily reporting emails, today there was an error, and when i debug it i found out something odd. i have this simple query ; var rslt = (from p in db.someTable where (p.STATS_DATE != null && […]

Store and query user preferences (name/value pair) in a list with enum types and LINQ

Let’s say I have some user-configurable settings I want to save in SQL Server and query/manipulate with LINQ: public enum PreferenceType { NamePublic, EmailPublic, BirthdayPublic, Visibility } The first three are booleans but Visibility I would like to be its own enum… public enum Visibility { Normal, Hidden, FriendsOnly } I have member data in […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.