linq-to-sql

Entity Framework vs Linq to Entities vs Linq to SQL

Hi I read a lot articles about how to work with database in WPF .Net 4 application. As I understood, the main two technologies are: Linq to SQL (L2S) Entity Framework (EF) but sometimes I also can see mention of Linq to Entities (L2E) technology, but can't find clear explanation what difference between EF and L2E. So, my question i...

Linq to SQL in vb.net 2008: Sum two fields from different tables

I have got two tables 1.ItemsSoldOnShop, 2.ItemSoldOnInternet. Each has partNo, quantity, date, etc fields. All I want is to sum total quantity sold for a given partNo and date range in two different Linq to SQL quaries in vb.net 2008 1. Monthly sum 2. Just total quantity. I dont need to look at master table which is PartMaster. I did f...

Linq queries on dB and using custom Comparers

Whats the use of using custom comparers in Linq queries? Are they beneficial or are they just an overload on the server. So i am talking about queries like IEnumerable<Class> GetMatch(Class comparerObject) { return Session.Linq<Class>().Where(x=>new StringComparer<Class>().Equals(x,comparerObject)) } and this is how my stringcomp...

Combining 2 LINQ into one call

Hi, I'm using 2 similar LINQ queries to return a result, the only difference is the where clause (&& s.OptIn == "Yes"). Is there a way to execute this with only one query? Instead of having a result of A 2 B 3 and another result of A 1 B 1 I want to have A 2 1 B 3 1 Here's the LINQ: var result = from s in...

How to represent an sql exists() command in LINQ

I have a SQL problem that I use over and over again, but now that I need to do stuff more in LINQ. How do I do this? Is there a site that converts your sql to linq? conn.Open(); SqlCommand command = new SqlCommand(); command.Connection = conn; //query command.Parameters.Add(new SqlParameter("@email", email)); //else command.CommandTex...

Update a many to many relation Linq to Sql

Hi I use Linq to Sql and have trouble of how to update a many to many relation. My scenario: A product is specified by one or more items. When I create a Product, i just select the needed items and they are added by: product.ProductItemRel.Add(itemRel); But what is the best practice when i need to update?. I could make my own updat...

Help using LINQ to select all elements that match all elements on a linked table that are inside an array

This ones a bit odd so I'll try and explain it first in plain English. I have three tables. TBL_PROFILE TBL_LANGUAGES TBL_LANGUAGES_LINK where the relationship is TBL_PROFILE --> TBL_LANGUAGE_LINK <-- TBL_LANGUAGES so if a person speaks 3 languages, they would have three entries in TBL_LANGUAGE_LINK. Basically I'm passing a string ...

How do I update Linq intellisense when I alter my table?

Suppose I make a change to a sproc or a Table that would require me to update previously generated Linq statements. How do I refresh this auto-generated code? ...

How do I get property value from property name in Linq to Sql?

I have generic repository. There is a method Save() to persist entity in db. I want to check primary key through Table.GetPropertyValue("ID", entity) - how i should implement it? private Table<T> Table { get { return db.GetTable<T>(); } } public void Save(T entity) { if (Table.GetPropertyValue("ID", entity) == 0) { ...

What's new in Linq to SQL in .NET 4.0

Does anyone know if there is anything new in LINQ to SQL in the 4.0 Framework? I know they said LINQ to SQL was not going to be supported anymore in favor of pushing the Entity Framework, but maybe they added new features or fixed some bugs. ...

Dynamic Linq - query a schema that is only known at run time?

I know with dynamic linq you can construct expressions dynamically in the same way that you might build and execute a dynamic SQL statement - e.g. a dynamic where clause or a dynamic select list. Is it possible to do this in cases where the schema is not known at compile time? In a database I'm working with users can define their own en...

LINQ-to-SQL performance question

Hi -I am getting an IQueryable from my database and then I am getting another IQueryable from that first one -that is, I am filtering the first one. My question is -does this affect performance? How many times will the code call the database? Thank you. Code: DataContext _dc = new DataContext(); IQueryable offers = (from o in _dc.Offe...

Dynamic LINQ help for sorting problem

I have a simple IEnumerable collection of Order objects. I want to write a generic sort function that accepts the collection and a sortkey that corresponds to a property on an Order object. I don't want to hardcode the sort instructions for every property. How can I build a dynamic LINQ string that automatically generates the LINQ for me...

Linq to SQL vs Access SQL - Why aren't Take() and TOP the same?

Sorry I couldn't come up with a better title, but it's kind of a convoluted question to begin with. I'm in the process of converting an access database over to the web, and I'm using linq to sql. In the access database, there is a SQL function that returns the top 3 records, ordered descending by # of individuals collected. For examp...

C# LINQ: How to stack LINQ queries correctly

I have a form that allows the user to perform a myriad of searches. The table(s) that need to be joined differ depending on the search criteria entered. (My example below is very simplistic because both tables use the same sub-tables to join on, but the actual problem is not as simple.) I've been using a technique I call LINQ stacking...

SQL Server stored procedure and Linq-to-SQL

I'm working on a project right now where we have to implement all communications to the database via stored procedures. We are using Linq-to-SQL, so all the database entities are in place. My question is how you could write a stored procedure that returns an entity, if this is possible. Example, we validate a user when he's logging in w...

Not Equal in LINQ?

Table Reords: TableA SerialNUmber Status 001 OK 002 N/A TableB SerialNumber Status 001 OK 003 N/A var ret = (from p in TableA.AsEnumerable() join q in TableB.AsEnumerable() on p.Field<string>("SerialNumber") equals q.Field<string>("SerialNumber") sele...

LINQ fails to create database

The following code example fails randomly on some PC's. On other PC's the problem cannot be reproduced. All PC's are running .NET 3.5 SP1 on Vista SP1. string connection = @"Data Source=PCNAME\SQLEXPRESS;Database=TestDatabase ;User Id=sa;Password=ThePassword;"; TestDatabase db = new TestDatabase (connection); if (!db.DatabaseExists())...

Select last value in a month for all given IDs using LINQ

This question is the second part of another question of mine, but this time focused on LINQ-to-SQL. I have 2 tables, one containing meter IDs, and another containing measurements for some of the meters in the first table. This is the table structure: MeterConfig: MeterID (int) MeterNumber (char[16]) Type (char[25]) Readings: Mete...

TextBox.Text Changing Unexpectedly

I'm updating a LINQ object prior to SubmitChanges. The values of the object's properties are being taken from a series of TextBoxes. When I read in one specific TextBox, another TextBox changes its value with no apparent cause. //... loc.Lattitude = txtLocLat.Text; // txtLocLong.Text changes to previous value loc.Longitude = txtLocL...