linq-to-sql

How do I get the TotalRowCount from a LinqDataSource into a Literal?

I have a LinqDataSource that I use to calculate the number of rows in a table. I would like to update the value of literal with the number, with the following code, taken from MSDN (linqdatasourcestatuseventargs.totalrowcount.aspx): protected void linqDataSource1_Selected(object sender, LinqDataSourceStatusEventArgs e) { Literal1.Te...

How to get the best performance from LINQ querying several rows in a table

my goal is to get lots of rows from a translation table. I use an ID to get a subset of the table (say 50 rows) then I use another ID to the rows I want from this subset. Using typed datasets I do the following to get the main dataset: funderTextsDS.tbl_funderTextsDataTable fd = (funderTextsDS.tbl_funderTextsDataTable)(new funderTexts...

Help needed for LINQ To SQL operations (insert/update) with nested POCO's

Ok well I've been trying to convert my model to use LINQ but didn't want to throw away my current DTO's and their interfaces which are scattered through the domain. I managed to find this blog post which has outlined the process quite nicely: Achieving POCOs in LINQ To SQL I have the managed to get the retrieval of records to objects ...

How do I verify that my LINQ-to-SQL model matches the database schema?

I am absolutely new to the .NET world, and started with C# on friday. I have some experience with database apps, though. We will go with LINQ-to-SQL for a medium scale project. I am used to generating my schema from classes and keep track of changes with subversion and equivalents to Ruby's Migrations. There obviously is no easy way to ...

How can I add an additional object to the results of a LINQ query ?

I have the following code that I need to add an additonal object to after the results have been retrieved from the databse. Any Ideas on how I might to this ? public IEnumerable<ProdPriceDisplay> GetShopProductsPrices() { //ProdPriceDisplay ProdPrice = new ProdPriceDisplay(); var Products = from shop in db.SHOPs ...

GetModifiedMembers returns empty array

In this code: DataContext dx = new DataContext( string.Empty ); MockLinqDataObject foo = new MockLinqDataObject(); dx.GetTable( foo.GetType() ).Attach( foo ); foo.PK = Guid.NewGuid(); // always returns empty array ModifiedMemberInfo[] arr_Result = dx.GetTable( foo.GetType() ).GetModifiedMembers( foo ); bool isOk = ( arr_Result.Length ...

LINQ To SQL entity objects as domain objects

Hi everyone. Clearly separation of concerns is a desirable trait in our code and the first obvious step most people take is to separate data access from presentation. In my situation, LINQ To SQL is being used within data access objects for the data access. My question is, where should the use of the entity object stop? To clarify, I ...

Linq to SQL and Entity Framework Diffrences ?

Anyone know what is the diffrences between those 2 asumming I'm using SQL Server as my database ? Are they the same ? ...

How can I force Linq to SQL NOT to use the cache?

When I make the same query twice, the second time it does not return new rows form the database (I guess it just uses the cache). This is a Windows Form application, where I create the dataContext when the application starts. How can I force Linq to SQL not to use the cache? Here is a sample function where I have the problem: public ...

Best way to periodically remove a set of records with LINQ to SQL

This is my first crack at a method that is run periodically during the lifetime of my ASP.NET application to clean up expired sessions stored in my database. It seems to work pretty well, but the software engineer in me doesn't feel "right" about this code. I've been working with LINQ to SQL for a few months now, but I'm not very confide...

Design Question: Building a DAL for a performance critical, high volume application

I'm working on a large scale performance critical asp web application with a pretty much denormalized database (lots of data is duplicated across tables for performance reasons). The application is highly performance critical and large. There is almost no sense of any kind of n-tiered design. I can't touch the database, it's carved in st...

linq to sql not putting quotes around strings in where clause

I have a simple Linq to SQL query that is pulling data with a where clause by a string. The result query doesn't put quotes around the string. Example string name = "John"; var query = from n in db.Names where n.Name == name select n; the result is .... WHERE ([t0].[Name] = John) .... Network is a varchar(10) and TNT was populate...

LINQ to SQL - Nullable INT in ForeignKey = "Cannot create an association..."

I have a table that has a primary key that's an INT... I have another table, that has a foreignkey relationship to that first table, but it's a NULLABLE INT. This is perfectly ok, and 100% acceptable to SQL... however LINQ to SQL is complaining about mismatched types ("int to Nullable[int]"). Error Message: Cannot create an association...

Linq to SQL update not working using Repository pattern

I am using asp.net mvc for an application. I've taken some guidance from Rob Conery's series on the MVC storefront. I am using a very similar data access pattern to the one that he used in the storefront. However, I have added a small difference to the pattern. Each class I have created in my model has a property called IsNew. The i...

How to lazy-load a single property on a Linq entity?

I'm hand-coding Linq to SQL Entities and have a large XML column that I don't want loaded each time this entity is loaded, as it's infrequently used. Everywhere I search, I see that the Linq to SQL designer provides a "Delay Loaded" property, but the ColumnAttribute class doesn't have any hints as to how this is implemented. I've gather...

How to get Castle MonoRail's DataBinder/SmartDispatcherController to bind against types containing properties that are interfaces?

We're using interfaces to represent entity classes in our domain model. We have concrete implementations of these by virtue of using LinqToSql. We have added a factory method to each LinqToSql class which our service layer uses to instantiate a new entity (note; as opposed to the controller's DataBind attribute doing it). MonoRail's d...

Any clever way to fix 'string or binary data would be truncated' warning with LINQ

Is there a clever way to determine which field is causing 'string or binary data would be truncated' with LINQ. I've always ended up doing it manually by stepping through a debugger, but with a batch using 'SubmitChanges' I have to change my code to inserting a single row to find the culprit in a batch of rows. Am I missing something ...

Rollback a stored procedure call from inside a transaction using LINQ-to-SQL?

I have a C#.net winform program which runs with a SQL Server database. I am using LINQ-to-SQL. Is it possible to rollback the call to one or more stored procedures inside a transaction within my program using LINQ-to-SQL? Initially I thought it would make sense to manage the transaction inside the stored procedure but if I need to r...

LINQ To SQL Weird Join Issue

I have a simple database with two tables. Users and Configurations. A user has a foreign key to link it to a particular configuration. I am having a strange problem where the following query always causes an inner join to the Configuration table regardless of the second parameter value. As far as I can tell, even though the "UserConfigu...

LinqToSql .Contains and nvarchar vs varchar parameters -> index conversion plan

I have a just one table mapped in a datacontext. Here's the property and attribute on the column of interest: [Column(Storage="_CustomerNumber", DbType="VarChar(25)")] public string CustomerNumber { This column is, in fact, a varchar(25) and has an index. I've got some simple code: DataClasses1DataContext myDC = new DataClasses1Dat...