linq-to-sql

Can I make autogenerated properties "override" like I can do in Associations in LINQ to SQL

eg. House.CityID House.City I can make the City property "override" as its an association. Can I do the same to House.CityID make it "override" ...

Why can't I reuse a function in LINQ to SQL

Why does the below LINQ to SQL statment throw an exception? I have a function bool TrimAndCompare(string s1, string s2) { return customer.CustomerID.Trim() == customerID.Trim() } ...some other function i call the above function in my linq statement var customers = from customer in _context.Customers wher...

How linq to sql works with sql connections?

Hi folks. What is the best way of working with linq data context? And how does link work with sql connection (when does it open connection and when does it close connection)? Should I aloways use using statement when i work with data context? Sorry for list of questions. Thanks in advance. ...

ASP.NET Caching at data access layer (best practice question)

Hello, I currently have a LINQ 2 SQL data model and a supporting 'Passenger' repository class. The repository is as follows (off the top of my head so the code may have errors): public class PassengerRepository { public static Passenger GetPassenger(int passengerId) { Passenger p = null; // Linq to sql code to ...

SQL Database with XML fields, select according to XElement using LINQ

I have a table in an SQL database, where the table configuration corresponds to ID Name string data xml where the datafield might (but not necessarily) contain a descendant element <config>Some value...</config> Using LINQ I want to select all the rows that has a data xml element which contains the config element with a value of......

How long should I keep my LINQ DataContext around? ASP.Net page

I'm working on a ASP.Net webform app and I am wondering how long I should keep my data context around. Currently I create a context on each page load, and that context is used in every db access for the entire page load. Should I be using a context only in each method that needs it, and dispose at the end of the method? I understand that...

LINQ to SQL String Joining with a null value

My query looks like this: var products = from p in Products select new { ProductId = p.ProductId, Description = p.Quantity + " x " p.Price + ", " + p.ItemDescription }; The reason I am joinin the Description in the query, is I am doing this for multiple q...

LINQ to SQL Covariance - is this the right way to do this?

I have several database - Elephants, Giraffes, Gorillas, etc - each of which has an Inputs and Results table named ElephantInputs, ElephantResults, GiraffeInputs, GiraffeResults, GorillaInputs, GorillaResults, respectively. I can't control the table naming. I'm using LINQ to SQL to automatically generate the ElephantInputs, ElephantResu...

How can I get access to or replace LINQ to SQL's IdentityManager?

I need to find out if an object with a particular primary key is already attached to a DataContext and get the entity from the DataContext if it is attached. Is there any way at all to do this that doesn't require Reflection with full trust? Ideally, I would like to call GetCachedObject(), but I'd have to use reflection to get at that,...

Very simple LINQ query, passing in textbox value to the where clause

I want my LINQ query to count the number of instances a member is present in a table based on what the user enters into a textbox. As a result, I have the following protected void btnSubmit_Click(object sender, EventArgs e) { LoginDataContext lg = new LoginDataContext(); int logincheck = (from r in lg.tblOnlineReportingLogins ...

Join tables multiple conditions - compare dates - Linq

I'm trying to do a join on two tables based on multiple conditions, the problem is I'm not able to compare the date fields. The date is stored in datetime format in DB and I want all the records on a particular date, when I do this in as shown in the code below, I get this exception .. Method 'System.String ToShortDateString()' has no s...

checking, operation successful after any LinqToSql operation

We normally use these statements to add anew record to database. MyDataContext.InsertOnSubmit(AnObject); MyDataContext.SubmitChanges(); Other than using stored procedure(can return a value by "Return / Output"), is there a way to return a value indicating, operation was successful ? probably, Linq own methods / functions Any idea, Th...

Linq to SQL table inheritance in ASP.net Dynamic Data

I have a Linq to SQL data model that uses single table inheritance. I created a new ASP.net Dynamic Data web site with all table scaffolding enabled, but I can't see any of the derived classes in my data model being scaffolded. Is this by design? ...

Convert this SQL query to Linq (Not Exists + sub query)

I would like this SQL to be converted to LINQ. (it shouldl select rows from input which do not exist in table production based on 3 columns. If a column in both tables contains NULL, it should be considered as having the same value) SELECT i.* FROM INPUT AS i WHERE NOT EXISTS (SELECT p.Agent FROM Production AS p WHERE ISNULL(i.CustID,''...

The member has no supported translation to SQL. When trying to access a property in my Partial class in the LINQ to SQL statement. Lamda expression?

I have 3 tables in my database Country City House Country table looks like CountryID Name City table looks like CountryID CityID Name House CountryID CityID HouseID Name I use LINQ to SQL and the above tables become classes and have their properties etc. Now I have my own abstract class called Location And cr...

"No supported translation in SQL" Linq workaround?

Currently im trying to make my query short with reusable peice of code like this to check for post if it's eligible to display. // Logic to check if post is eligible for display public bool isEligibleForDisplay(Post n) { var pubDate = n.PUBLISH_DATE ?? DateTime.MinValue; var endDate = n.END_DATE ?? DateTime.M...

sum 2 fields from one table in one Query without group by

Suppose we have a table T with two fields A and B, both decimal. How would I wite an L2S query that produces this T-SQL ? SELECT SUM(T.A), SUM(T.B) FROM T The idea is NOT to pull in all the records and do a sum in memory... ...

Switching Database in LinqToSql

How can we change the underlying database for Linq based WebApp ? for example: When we release our web application, say to release from production, if using ADO.NET, it is as simple as modifying connection string in web.config to point towards the live Database in use. The databases are almost identical, other data stored.. What and h...

Why is dbml generating extra classes

i am having a small problem here. The table which dbml (LinqToSql designer) is using has columns (Foreign keys), for which it generates two objectsfor the coressponding Blogs table (1:1 association) in DB lmost same, like Table Authors: AuthorID INT, Name varchar(20), BlogID INT And TABLE BLOG: BlogID INT, Name varchar(MAX) Bl...

Reporting ..how to create...

I would like to create a report document, i could take in mind your suggestions. The idea is that i need to use a background image where this is the design form and on this (image - form paper) i want to put fields on specific locations. I am beginner on reporting and printing. Could this created using a picture box and making it as lar...