linq-to-sql

How to ignore case with LINQ-to-SQL?

I'm having problems with getting data using LINQ-to-SQL. I use the following piece of code to look up a user for our web app (user name is email address): var referenceUser = db.ReferenceUsers .SingleOrDefault(rf => rf.Email == values["emailAddress"]); If I type [email protected] I get a ReferenceUser however if I type tESt@tES...

How do I export a DBML diagram from Visual Studio into an image?

I have a very pretty DBML diagram that I would like to preserve in our Design Documents. How do I get an image showing all of the tables in one go? I found http://stackoverflow.com/questions/1686767/how-to-export-visual-studio-2010-uml-modeling-diagrams but the slightly elegant solution of copying all the items and pasting them into an ...

Confused on Getting an int out of a var from Linq2Sql

I am just learning Linq and ran into a problem. For some validation, I am getting the last odometer reading from our database and need to compare that to the next reading. The odometer reading is an int on the incoming data and double on the database (changed to int on the dbml file). Below is my code: private bool IsValidOdometer(stri...

LINQ to SQL and Self Related Table

We have the following test model in the dbml file: For the test case there are 4 records in the table, 1 parent, 3 children. We are looking for the siblings of a specific record, including the specific record. using (var db = new TestDataContext()) { var query = from f in db.Foos where f.Name == "Two" ...

Override SQL generated by LINQ to SQL?

Is it possible to override the SQL generated by LINQ to SQL, for optimisation purposes? ...

What should I know before moving from Datasets to Linq2Sql ?

Finally, I'm taking a decision to shift from conventional ado.net datasets to Linq2Sql. I'm not migrating my existing projects to Linq2Sql but I'll be using Linq2Sql in new projects from this point forward. I'm responsible for primary design of applications where I work so I look forward to have answers from you for things that I must b...

Linq To SQl Reference Keys behavior?

I have a database with some references, An example is a Customer Table has the AddressId integer column, and an Address Table has the Idenity Auto Generated Id column. I reference these as primary the Address "Id" and the Customer "AddressId". Now when i generate the dbml file or use SqlMetal, i get in the Customer entity two properties...

LINQ to SQL DataContext and Connection Problems

I am using LINQ to SQL for my website to access two databases. The first database is the website (which i'll call WEBSITE) data, the second is a history of transactions (which i'll call WEBSITE_HISOTRY). When I added a table from the WEBSITE_HISOTRY to my datacontext not so long ago i recieved some sort of alert that I clicked OK on (pro...

LINQ to SQL Where - how to mark methods untranslatable to SQL

As it is known, not every method can be translated into SQL via LINQ-to-SQL. These methods or properties being met in expressions causes exception at runtime - 'The member 'PropertyName' has no supported translation to SQL' Evidently, these properties must be calculated on server-side. But is there any approach to do it automatically? ...

LinqToSql - Bit of a strange behavior

Hi, I am trying to run the following code. But the code breaks Dim complaints = From comp In Me.Db.Complaints _ Let varX = GetVariations().WithVariationId(If(comp.ItemPropertyXVariationId, 0)) _ Let varY = GetVariations().WithVariationId(If(comp.ItemPropertyYVariationId, 0)) _ Select New Hogia.Retail.POS.Data.Complaint(...

Check if I have already inserted a particular record

I am going through a massive list of business objects and inserting them into the database using Linq-to-Sql. Some of the business objects contain a payment method record (cheques, credit card etc..) When it comes to adding a payment method, I want to check to ensure I havent already added it, cos otherwise it will rant at me when I co...

Binding textboxes to properties of a comboBox.SelectedItem

I'm using winforms and I've got a comboBox that represents an IQueryable. Below the combobox is a series of textboxes that I would like to be bound to the currently selected from the combo box. Here is my code. public partial class TestForm : Form { public DataClassesDataContext DataContext; public IQueryable<T> datasource;...

Using LINQ to SQL; How Do I Insert a Row in a Table Without Setting all Column Values?

So I'm doing something like this, and I need to specifically NOT insert the value for one of the columns, a uniqueidentifier that is defaulted to newid() in the database. How do I do this? The following code is what I want, but doesn't work because the tagID column is getting defaulted to new Guid() -- all zeros and SQL server obviously ...

Does AutoMapper support Linq?

I am very interested in Linq to SQL with Lazy load feature. And in my project I used AutoMapper to map DB Model to Domain Model (from DB_RoleInfo to DO_RoleInfo). In my repository code as below: public DO_RoleInfo SelectByKey(Guid Key) { return SelectAll().Where(x => x.Id == Key).SingleOrDefault(); } public IQue...

Trouble with LINQ databind to GridView and RowDataBound

Greetings all, I am working on redesigning my personal Web site using VS 2008 and have chosen to use LINQ to create by data-access layer. Part of my site will be a little app to help manage my budget better. My first LINQ query does successfully execute and display in a GridView, but when I try to use a RowDataBound event to work with t...

how to cast nullable tinyint in linq to sql ?

I want to cast Nullable Tinyint column to int value in Linq to SQL ? ...

LINQ to SQL not worked in Window application

Hi Friends, I have created LINQ to SQL Class and trying to insert one record in application but unable to save record in database table in window application Table Name : Test I have two column in table 1) TID Type INT , Primary Key , Identity column 2) Title Type Varchar(50) I have written below code to save new record in to tabl...

Shouldn't i cast Linq To Sql entity table to its real type?

When i call "f_CategoriNewsGet" function from Page_Load method I'm getting null. But i can see tblNewsler object is full with objects before return line. protected void Page_Load(object sender, EventArgs e) { var tblNewsler = News.f_CategoriNewsGet("ÇEVRE", 18); // return object is always Table<News> tblNewsler1 = tblNews; r...

Linq to SQL Search Query

Hey, I have a table of news, and I want to allow the user to search in it. Something like this: News.Where(p => p.Title == user_query); ...that will allow more advanced queries, like Differences Between "Linq to Objects" and "Linq to SQL" queries, etc. Also it should be incase-sensitive. Any ideas? Thank you. ...

LINQ to SQL Sequence contains more than one element

Hi all I am getting an error when trying to delete a record from the database. Here is my current deletion code: Dim BAToRemove = From i In uDC.BookAuthors _ Where i.authorID = intAuthorID _ And i.bookID = intBookID _ And i.main = "N" _ Select ...