I've used LINQ to SQL in a unit testing project to mock some test data. I've changed the database name today and consequently the LINQ to SQL code doesn't work any more. I get the following error 'System.Data.SqlClient.SqlException: Cannot open database "XXX" requested by the login. The login failed'. I've tried changing the Connection p...
I've done a brief search of this site, and googled this, but can't seem to find a good example. I'm still trying to get my head around the whole "Lambda Expressions" thing.
Can anyone here give me an example ordering by multiple columns using VB.Net and Linq-to-SQL using a lambda expression?
Here is my existing code, which returns an o...
I need to translate the following Code to an Expression and I will explain why:
results = results.Where(answer => answer.Question.Wording.Contains(term));
results is IQueryable<ISurveyAnswer>
Question is ISurveyQuestion
Wording is String
The problem is, Question is not always the name of the LINQ to SQL property.
This will give me t...
I am trying to create a generic base repository for my Linq2Sql entities. I'd like to implement a generic FindAll() method like so.
class BaseRepository<T> : IBaseRepository<T>
{
private readonly FooDataContext _ctx = new FooDataContext();
public IQueryable<T> FindAll()
{
return _ctx.T;
}
public void Add(T ...
Hey all,
I have a DataView in which I would like to sum a column called "Amount"
Now I know I can iterate thru the columns and get the sum but I was wondering if is possible using Linq to Sql?
String sum = Linq to Sql stuff here (doesn't have to be a string, can be any type)
Thanks,
rodchar
...
I seem to be having a problem when using Linq to Sql in which the Where method adds a string reference to the criteria list. When the reference is changed, it produces erroneous results. For example, the code snippet below when used with the input text 'John Smith' returns all records whose name contains 'Smith'
var qry = from c in ct...
I’m looking for some advice. I recently wrapped up a project where I inherited some terrible code. I got the application running but it’s safe to say there are a number of performance and design issues, specifically with the advanced search functionality. I have now been asked to do a very similar project but much larger in scale. I have...
I have many-to-many relationship in LINQ to SQL scheme: Products table, Categories table and ProductCategories table (ProductId, CategoryId fields).
Product prod;
EntitySet<Category> cats = prod.ProductCategories;
Now I have a list of category ids (catIds) and I want to set (overwrite) them as categories of a single product in one ope...
Consider the IEnumerable extension methods SingleOrDefault() and FirstOrDefault()
MSDN documents that SingleOrDefault:
Returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.
whereas FirstOrDefault from MSDN (presumably ...
I'm sure this has been answered but I can't find it.
Say I have three tables;
Projects
Id <= unique key
name
Attributes
Id <= unique key
Name
ProjectAttributes
id <= unique key
ProjectId
AttributeId
I'm using a dbml file and I have all the associations drawn up within the dbml.
So how in my view, do I itterate through al...
I use an SQL varchar field to store my datetimes and would like Linq-to-SQL to store DateTime fields using ToString("o").
[Column(Name = "inserted", DbType = "varchar(30)", CanBeNull = false)]
public DateTime Inserted { get; set; }
A Linq-to-SQL insert will result in a format of "mm/dd/yyyy HH:mm:ss". I'd like to customise the datet...
Is it possible to get a LINQ to SQL DataContext to run completely in-memory? Without it touching the database?
I am doing some very rapid prototyping, and want to minimize the surface area for major changes since the UI is changing so fast. However, the data model already exists.
Data access is handled through the use of I[Model]Reposi...
Hey guys,
I have a WPF application which tightly coupled to linq2sql through WCF. It now turns out the Customer would like some sort of Offline mode using an xml file structure.
Lets say I have a Customers Table, Each Customer would have many Orders, with each order only belonging to one customer, so In my table design I would have a f...
Hi,
I have a User entity which represents a User table in my database. This table has a field called ManagerID which references another User record (basically an employee to manager mapping). Each User will also have a reference to another table which can have multiple entries, for the sake of this example we will call it Records.
So ...
I call a stored procedure via Linq-to-SQL. This stored procedure simply processes data that I've already inserted into another table. On large data sets, I get a timeout exception:
"Timeout expired. The timeout period elapsed prior to completion of the operation
or the server is not responding."
I can't do anything to speed the store...
As mentioned in this question, "LINQ to SQL allows table mappings to automatically convert back and forth to Enums by specifying the type for the column - this works for strings or integers." However, I am having trouble with this when using stored procedures (instead of auto-generated SQL) to create and update entities.
In my database...
I have a very complex Linq to SQL query that returns a result set from a Microsoft SQL Server database. The query is created using syntax similar to:
Dim db as MyDataContext = MyGetDataContextHelper()
Dim qry = From rslt in db.MyView Select ColumnList
If userParam1 IsNot Nothing Then
qry = qry.Where(lambda for the filter)
End If
e...
We have several classes with multiple 1:1 Relationships for quick joins, and while this works fine for anonymous types for tabular display, I'm unsure how to fully populate the type in a single linq query.
We have these properties either because it's an off 1:1, or we don't want to query through a child collection to find a "primary" ev...
I had a client ask for advice building a simple WPF LOB application the other day. They basically want a CRUD application for a database, with main purpose being as a WPF training project.
I also showed them Linq To SQL and they were impressed.
I then explained its probably not a good idea to use that L2S entities directly from their B...
Hi,
I have a grid which is binded to a list of objects using LINQ to sql.Now, the grid is editable.So, user can make changes to values in any column.But, if the user wants to cancel,I want to revert changes to the values of objects, and the grid should show original values(without hitting the database).Anyone has done this? How to manag...