linq

Multiple WHERE's in same LINQ 2 SQL Method

I have the below LINQ Method I am trying to create. The issue seems to be the Second WHERE clause. I am getting this error --> Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<MatrixReloaded.Data.CMO.tblWorkerHistory>' to 'bool' I also had && there vs WHERE but I was getting a similar error. I don't NEED anyth...

Locking Databases

Environment: SQL, LINQ, C# I have 2 WinForms running on different computers. They all hit the same database, and it's extremely critical that these forms don't affect the state of the database. I have a couple of questions. WinForm1, the linq queries in this form are all try/catched, if there is a concurrency conflict, I believe thi...

LinqDataSource dynamic parameters - forcing an OR with WhereParameters

In my "selecting" statement I need to add two dynamic parameters when using the LinqDataSource's WhereParameters collection: e.WhereParameters.Add(param, True) However, the system adds these parameters as AND, but I want to perform an OR where either parameter 1 OR parameter 2 is true. How can this be done? ...

Selecting multiple one to many relationships in LINQ to SQL using outer joins

I'm using .NET 4 and VS 2010 and have the same issue in .NET 3.5/VS 2008 The structure: Table 1: Call Table 2: AddressChangeRequest Table 3: CallNotes A single Call can have many AddressChangeRequests and many CallNotes. A Customer (customerKey) can have many Calls. The LINQ code: return db.Calls.Where(c => c.CustomerKey == '....

Enhance this LINQ query for readability and performance?

I'm not the greatest with LINQ, but I'm trying to retrieve all the ModuleAvailabilities where the academicYear is the current year. Are there any improvements to be made here? pathway.PathwayFoundationModule.Attach( pathway.PathwayFoundationModule.CreateSourceQuery() .Include("Module") .Include("Module.ModuleAvaila...

Understanding .AsEnumerable() in LINQ to SQL

Given the following LINQ to SQL query: var test = from i in Imports where i.IsActive select i; The interpreted SQL statement is: SELECT [t0].[id] AS [Id] .... FROM [Imports] AS [t0] WHERE [t0].[isActive] = 1 Say I wanted to perform some action in the select that cannot be converted to SQL. Its my understanding...

Linq to SQL using StoredProcedure - How to return a value (insert, update, delete)

How do we return a value from a stored procedure here is my sp looks like: create proc dbo.spInsertGroup @ID uniqueidentifier @GroupName varchar(100), @IsActive bit AS BEGIN insert into tblGroup values(@ID, @GroupName, @IsActive) Select @@IDENTITY AS ID END based on the return value i want to show the user some kind of feedback ...

Create new Linq SelectMany extension method

I am using Linq.Dynamic. I have already added another SelectMany extension to all for creating a new anonymous object with the data. But, I have ran into another issue that I can not seem to solve. I want to have extension method chaining as follows, but using the dynamic methods: var customerandorderflat = db.Customers .S...

Get the set of grouped values as a list using linq

I am taking a datatable and finding all the rows for a specific key that have fewer than three entries in the table for that key value. I can do this fine and it returns a grouping with the key being the id I want to group on and a list of the datarows that, for each key value, don't exist at least three times. Now I want to get a straig...

The member <some column> is not supported in SubSonic

Hello, I am using the T4 templates of SubSonic 3.0 to generate classes and such for me. Well in my database I have a Zipcode table with these columns ZipCode_rid Zipcode (the actual zipcode in number format) State etc Well, when the T4 templates run, instead of having a column like Zipcode.Zipcode I get Zipcode.ZipcodeX. Then, when t...

How can I do case insensitive string search with Linq and SQL Server?

Here is my current code for searching tags: public JsonResult TagSearch(string term) { if (term == null || term == "") return Json(""); var tags = (from t in _session.All<Tag>() where t.Name.Contains(term) select t.Name).Take(6).ToArray(); return Json(tags); } How could I do case insensiti...

Find index of a key? Dictionary .NET

I need to do currentKey+1. So i would like to find the index of the key value and get the next key (or first if at end). How do i find the current index of the key? I am using a Dictionary<int, classname> and i looked for .Find or IndexOf with Linq to no avail. ...

Query property of enum collection mapped as element

Hi, I have the class with enum property collection: public enum PropertyType { Apartment, Townhouse, AndSoOn } public class Company { private readonly ISet<PropertyType> desiredPropertyTypes; public virtual ISet<PropertyType> DesiredPropertyTypes { get { return desiredPropertyTypes; } } // other stuff... }...

ObjectSet query not returning added EntityObject until SaveChanges() called

I think I'm missing something very simple here. I have an EF4 ObjectContext that contains an ObjectSet of type Thing, which is mapped to a table in my database called Things. If I add a Thing to the Things ObjectSet, that Thing is not visible in Things until I call SaveChanges() on the ObjectContext. So, in the following test fixt...

How to use Linq objects to validate a view in MVC 2

Hi I would like to use Linq and strongly typed views in the right way. at the moment I do the following: Make a Model to verify agianst: public class Menu { public int Id { get; private set; } public string Text { get; private set; } public string Action { get; private set; } public string Controlle...

Nerd Dinner pagginated list - how do I add a linq orderby clause dynamicaly? ANYONE????

Hi, I have implemented nerd dinner method of paging- which works great. But I want to be able to dynamically be able to order by certian fields. How would I go about implementing this. Here is my code? Controller: PaginatedList<Classifieds_Ads> pageOfClassifieds = new PaginatedList<Classifieds_Ads>(classifiedsRepositry.GetClassified...

LINQ to Entities does not recognize the method 'Int32

public ActionResult ReadXMLDevices(int groupID) { var query = from k in XMLEntities.unassigneditems where k.DevOrAcc == true && k.Group == groupID select k; var view_query = from i in query select new GetFreeDevices { MArticleNumber = i.Artic...

LINQ Cache issue

Hi There I am pretty new to LINQ and having a issue with what seems to be irregular content caching. The website in question has 6 content areas of different subjects now on the odd occasion the content just blanks out to nothing or has the same content for all 6 areas. It will clear up this issue by itself over time or the only other w...

Expanding properties for an IQueryable query

I have a the following domain classes: public class Pony { public string Name { get; set; } public DateTime FoundDate { get; set; } } public class Person { public ICollection<Pony> Ponies { get; private set; } public Pony NewestPony { get { return Ponies .OrderBy(pony => ...

How do I bind multiple tables (or entities) to a datagrid and enable CRUD operations?

Hi all, Consider two tables, Product and Supplier. To get the required data for a grid view I need to do something like the following code snippet. SupplierID is a foreign key in the products table, but needs to be displayed in the user friendly SupplierName from the Supplier table. SELECT Product.ProductID, Product.ProductName, Produc...