linq-to-sql

Retrieving one objet by using GetTable method over DataContext

I have a class is inherited from DataContext to use Linq. public class Context : DataContext { public Context(string connectionString) : base(connectionString) { } } [Table(Name = "TableNameee")] public class ClassOfTable { } And i have another class which is mapped to a table. I am using context.GetTable<Clas...

Django ORM's "related data" loading behavior

In LINQ (I come from a C# background), you can manually load data for related tables via the Include("xxx") method from a in ctx.MainTable.Include("SubTable") select a; In the above code, every instance of MainTable is loaded and all the data for MainTable.SubTable is also loaded. If "Include" is not called, every returned MainTable'...

LINQ2SQL to DataTable

What is the easiest way of copying a LINQ2SQL table into an ADO.NET DataTable? ...

Need help for a more beautiful LINQ to SQL query

Following is a T_SQL query for AdventureWorks database: SELECT Name FROM Production.Product WHERE ListPrice >= ANY (SELECT MAX (ListPrice) FROM Production.Product GROUP BY ProductSubcategoryID) I try writing a LINQ query for this: var groupMaxPricesquery2 = from product in dc.Products ...

ASP.MVC ModelBinding Behaviour

This one has me stumped, despite the numerous posts on here. The scenario is a basic MVC(2) web application with simple CRUD operations. Whenever the edit form is submitted and the UpdateModel() called, an exception is thrown: System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException was unhandled by user code This occurs again...

ObjectDataSource with Composite Lists

I have one list that contains Student informations lsStudents = context.GetTable<Student>().Where(p => p.M_Id.Equals(1)).ToList(); And I have another one that contains Student Lessons lsMarks = context.GetTable<Mark>().Where(p => p.M_StudentId.Equals(1)).ToList(); I want to merge these lists to one ObjectDataSource to bind to a rep...

Help with LinqtoSql

Im using the Repository pattern and I want to write a method that receives a role and returns an Iqueryable of the users that belong to that role. (Im not sure if the right way would be to receive the role object or the role_id... in any case, how can I do this?? I dont like the query structure, I prefer the method structure of linq. use...

C# Covariance issue

I had a linq-to-sql generated domain entity that I cast to the proper interface like so: public IEnumerable<IApplication> GetApplications() { using (var dc = new LqDev202DataContext()) { return dc.ZApplications.Cast<IApplication>().ToList(); } } However I renamed the linq-to-sql table withou...

How can I page my LINQ to SQL result set?

Remembering MySQL could use the instruction "limit" to indicate where I was starting my result set and how many wanted to have included. Select * FROM Users Limit [start], [Length] How can I do this in LINQ to SQL? ...

Getting linq error with group

I am getting the following error when I add the linq grouping. Error 5 'System.Linq.IGrouping' does not contain a definition for 'Description' and no extension method 'Description' accepting a first argument of type 'System.Linq.IGrouping' could be found (are you missing a using directive or an assembly reference?) using (var db...

Getting Last rows from the result of Linq to Sql statement.

I couldn't get last articles of every writers in this statement. List<Editor> lstEditors = dataContext.GetTable<Editor>().Where(t => t.M_Active).Select(t => t).ToList(); var lstArticles = from article in DAO.context.GetTable<Article>().ToList() join editor in lstEditors on article.RefEditorId equals editor.EditorId select new ...

Linq to sql object is marking it to insert automatically

I'm making a clone of some entities to bound them to some grid and avoid the objects to be tracked for changes, something like: var cloneEntities = DataContext.SomeTable.FirstOrDefault(). SomeChildTable.Select ( x => new SomeChildTable { SomeProperty = x.SomeProperty } ); Some of the properties are not primitive types b...

Does LINQ2SQL make use of table indexes?

Does LINQ2SQL make use of table indexes when executing a query? ...

insert in dymanic update - linq to sql

I'm developing a dynamic data app, in which I'm trying perform insert RequestRevision during update of request (logging change of request, somthing like that) public partial class ProjectDataContext { partial void UpdateRequest(Request instance) { RequestRevision rv = new RequestRevision...

NullReferenceException when doing InsertOnSubmit in LINQ to SQL

In my database I have a table called StaffMembers when I bring this into my .net Project as through linq-to-sql an entity class StaffMember is created Now I have also created a partial class StaffMember in my project also, to add extra properties that I use in other top layers. eg. IsDeleted property. This partial class also inherits a...

Linq to SQL: How can I update a formview that has data from multiple tables?

Take a simple example: I have a customer table and an account table both with customerID field. I want to formview that can update data in both tables. FormView: First Name (Customer) Last Name (Customer) Address (Customer) AccountRate (Account) How can I do this with Linq to SQL? Do I just use Bind statements like Bind("Account.A...

linq to sql -get data from a table related to another

Im using linq to sql i have a Documents table and a FavouriteDocuments table FavouriteDocuments table has a documentsID fk and a ProjectID fk. given the ProjectID how do i get all the documents(from the documents table) that are a FavouriteDocument for that particular project. thanks ...

Using Repository Pattern, POCOs and LINQtoSQL with tables of multiple types

Firstly, my previous question will help give some back story. As stated in that question, I have a super-type table (if that is the technical term for it) and I have multiple sub-types in different tables - all with field unique to that sub-type. Events * Id * EventTypeId * AllEventTypes_Field EventType0 * EventId (FK) * EventType0_Fi...

can't insert new row into a child table with submit changes in a linq to sql app

I can't figure out the correct way to insert a new record in a child table. There's a single datacontext in the app and the target table (CustNotes) is a child of a table named Customer. There's a one to many association between Customer and CustNotes. The datacontext name is CustomerOrdersDataContext. Here's the code I'm using: priva...

How do you generate a WHERE...IN clause using LINQ2SQL?

Going backwards from SQL to LINQ2SQL is sometimes quite simple. The following statement SELECT user FROM users WHERE lastname='jones' translates fairly easily into from u in users where u.lastname='jones' select u But how do you get the following SQL generated? SELECT user FROM users WHERE lastname IN ('jones', 'anderson') ...