linq-to-sql

How to reference the SQL column description field through the DBML?

I would like the SQL column description property to hold the friendly name of the column to display to the users. Is there a way that I can reference this column property through the DBML? Update: We ended up writing a c# method that injects a space into a camel case string and renaming the DB columns to be more friendly. ...

if-else equivalent via linq-to-sql query in where clause c#

Hi guys, Basically I wanted to have an if-else statement in my linq to sql statement. var query = from d in database if(x == y) { where d.Attr = x } else { where d.Attr = y } select d; Any ideas? ...

Visual studio ORM designer option

linq to sql visual studio Object-Relational designer generates C# entity class names same as the table names (except pluralizing it). so if the table name is authors it generates entity class with name "author". If the table name is Customers it generates class with name "Customer". Is there any option that can be set to make the desig...

Exception handling in Linq to SQL for customers without orders

I have the following code to retrieve customer name, total (orders ), sum (order details) for reach customer in Northwind database. The problem with below code is that it raises an exception since a few customers dont have any entry in orders table. I know using the query syntax (join) the exception can be avoided. I want to know if th...

How to use different providers for Linq to entities?

I'm trying to familiarize myself a bit more with database programming, and I'm looking at different ways of creating a data access layer for applications. I've tried out a few ways but there is such a jungle of different database technologies that I don't know what to learn. For instance I've tried using datasets with tableadapters. Usin...

c# linq to sql join problem

i am trying to do using (UserManagementDataContext context = new UserManagementDataContext()) { var users = from u in context.Users where u.UserEMailAdresses.EMailAddress == "[email protected]" select u; return users.Count(); ...

Check username and password in LINQ query

this linq query var users = from u in context.Users where u.UserEMailAdresses.Any(e1 => e1.EMailAddress == userEMail) && u.UserPasswords.Any(e2 => e2.PasswordSaltedHash == passwordSaltedHash) select u; return users.Count(); returns: 1 even when there is nothing in password table. how come? what i am trying to...

linq to sql loadwith vs associatewith

what is the difference between loadwith and associatewith. From the articles i read it seems that loadwith is used to load addition data (eg all orders for the customers). While AssociateWith is used to filter data. Is that a correct understanding? Also it will be nice if someone can explain this with an example based explanation. ...

LINQ to Sql: Insert instead of Update

I am stuck with this problems for a long time now. Everything I try to do is insert a row in my DB if it's new information - if not update the existing one. I've updated many entities in my life before - but what's wrong with this code is beyond me (probably something pretty basic) I guess I can't see the wood for the trees... private...

How do I properly use LINQ with MySQL?

Possible Duplicate: LINQ to MySQL - what is the best option? I've been looking this up on Google for hours, but I haven't found anything conclusive. So far, I've seen a few paid options, an option with NHibernate, but most are marked as unstable or in production. Is there a stable implementation of LINQ for MySQL? ...

How can I prevent 'objects you are adding to the designer use a different data connection...'?

I am using Visual Studio 2010, and I have a LINQ-to-SQL DBML file that my colleagues and I are using for this project. We have a connection string in the web.config file that the DBML is using. However, when I drag a new table from my "Server Explorer" onto the DBML file... I get presented with a dialog that demands that do one of these...

same Linq for two tables

I need to do something like this, My two tables have the same signature, but different class so It suppose to work but it is not working. var myTable; if (booleanVariable == true) { myTable = table1; } else { myTable = table2; } var myLinq1 = from p in myTable join r in myOtherTable select p; In this ...

Does AsEnumerable() cache all result (LINQ)

When we call a query operator on a sequence, a sequence-specific operator gets called. I mean if i call Where<>() operator on IEnumerable<>, the operator that will be called will be defined in Enumerable class and if it's called on IQueryable<>, the one defined in Queryable class will be called. Consider the operator Reverse, defined ...

How to approach performance issues?

Hi, We are developing a client-server desktop application(winforms with sql server 2008, using LINQ-SQL).We are now finding many issues related to performance.These relate to querying too much data with LINQ , bad database design,not much caching etc.What do you suggest,we should do - how to go about solving these performance issues? On...

How to create Query syntax for multiple DataTable for implementing IN operator of Sql Server

I have fetched 3-4 tables by executing my stored procedure. Now they resides on my dataset. I have to maintain this dataset for multiple forms and I am not doing any DML operation on this dataset. Now this dataset contains 4 tables out of which i have to fetch some records to display data. Data stored in tables are in form of one to m...

Forcing LINQ to SQL to make one single call for all child rows

Let say I have a method (example taken from another post): public IQueryable<CityBlock> GetCityBlocks(){ var results = from o in db.city_blocks let buildings = GetBuildingsOnBlock(o.block_id) //returns Iqueryable select new CityBlock { BuildingsOnBlock = buildings, ...

Linq to Sql select from multiple table

Hello; I have a question about selecting from multiple tables in C# using Linq. Table structure is like this: TABLE A TableAID Column1 Column2 TABLE B TableBID TableAID Column3 Column4 So in code i have: List<string> myList = new List{"Test1","Test2"}; var myView = MYDC.TableA.AsQueryAble(); If I want to select records from tab...

LINQ to SQL - ToDictionary not supported - How do I pull results into memory?

var details= from row in databaseTable where row.id equals queryId select new { Dict = row.ToDictionary(x => x.Name, x => x.Value), }; When executing this LINQ to SQL I get the error; System.NotSupportedException: The query operator 'ToDictionary' is not supported. What I need to do is pull the row...

LINQ to SQL: NOTing a prebuilt expression

I'm building a library of functions for one of my core L2S classes, all of which return a bool to allow checking for certain situations. Example: Expression<Func<Account, bool>> IsSomethingX = a => a.AccountSupplementary != null && a.AccountSupplementary.SomethingXFlag != null && a.AccountSupplementary.Something...

Chain LINQ IQueryable, and end with Stored Procedure

I'm chaining search criteria in my application through IQueryable extension methods, e.g.: public static IQueryable<Fish> AtAge (this IQueryable<Fish> fish, Int32 age) { return fish.Where(f => f.Age == age); } However, I also have a full text search stored procedure: CREATE PROCEDURE [dbo].[Fishes_FullTextSearch] @searchtext nva...