linq-to-sql

LinqToSql - change table name attribue at runtime?

When you create a model using LinqToSql, the designer puts an attribute for each table class that looks like [Table(Name=@"dbo.Project")] At design time this is easy to change either manually or using T4 templates. Can this table attribute be changed at runtime? ...

Unpassable Where Clauses LINQ-to-SQL

As I'm struggling to learn LINQ I’ve managed to generate a SQL statement with "AND (0 = 1)" as part of the where clause. I'm just wondering if this result is common in poorly written queries and is a known issues to try and avoid or if I am doing something totally backwards to end up with this. Update public static IEnumerable<ticke...

LINQ to SQL - further modifying IQueryable result set with Contains

I am using LINQ to SQL and I am allowing users to set up the query via assigning values to queryStrings in the UI. I set up the primary query to return an IQueryable result and then keep refining the results set by continuing to act upon the resulting IQueryable object. Everything works fine and the code looks similar to this var result...

LINQ query help plz

I'm trying to convert this SQL query to LINQ: SELECT Items.p_Name Product, DiamondCategory.dc_Name Category, Diamond.d_Weight Weight FROM DiamondCategory INNER JOIN Diamond ON DiamondCategory.dc_Id = Diamond.dc_Id INNER JOIN Items ON Diamond.p_Id = Items.p_Id where Items.p_Id = 1 Union gives no results: var qry = (from d in myDatabas...

How to create an event type with the selected customer type using checkbox list (VB.NET, LINQ to SQL)?

I have 3 tables: CustomerType CusID EventType EventTypeID CustomerEventType CusID EventTypeID How to create an event type with the selected customer type using checkbox list using LINQ to SQL and VB.NET? dim newEventType = new EventType newEventType.EventID = 1 db.EventType.InsertOnSubmit(newEventType) db.submitchange() Then I ...

Foreign keys cause more queries?

Hi, I have 2 objects - Order and Product. On the Order only productID is saved and when I view orders I want to see the product name. According to ScuttGu blog this is easily done by using a template field with Eval("Product.ProductName"). However, when reviewing the actual queries I see that for each order a separate query is made. I...

Link To SQL Join Statement with or Clause

I have to following SQL Statement that I want to conver to LINQ Select F.FooName B.BarName From Foo F Inner Join Bar B on B.BarName = F.FooName OR B.BarName + 'hello' = F.FooName I have seen Inner joins in Link on multiple conditions with AND Clauses but not using OR The following is as far as I have gotten var myresult = from f ...

Binding LINQ query to DataGridView

This is very confusing, I use AsDataView to bind query result to a dgv and it works fine with the following: var query = from c in myDatabaseDataSet.Diamond where c.p_Id == p_Id select c; dataGridView1.DataSource = query.AsDataView(); However, this one results in an Error: var query = from item in myDatabaseDataSet.Items where it...

Parent Child Relationship Linq to SQL

I am using Linq to SQL and have tables like *ItemTable* ItemId Description 1 Root 2 Child 1 3 Child 2 4 Child of Child1 5 Child of Child1 *ItemChildTable* ParentID ChildId 1 2 1 3 2 4 3 5 What will be best way to model them using LINQ to SQL So that I can get a object r...

How to Insert one to many relationship using checkboxlist in VB.NET, LINQ to SQL?

I have 3 tables: CustomerType CusID EventType EventTypeID CustomerEventType CusID EventTypeID How to Insert one to many relationship using checkboxlist in VB.NET, LINQ to SQL? dim newEventType = new EventType newEventType.EventID = 1 db.EventType.InsertOnSubmit(newEventType) db.submitchange() Then I want it to automatically ins...

Is there a better way to handle validation in LINQ to SQL?

Are there any ways, besides throwing exceptions, that one can go about using the partial validation methods in LINQ to SQL to cancel the insert of a record? ...

Can we convert all SQL scripts to Linq-to-SQL expressions or there is any limitation?

I want to convert all of my db stored procedures to linq to sql expressions, is there any limitation for this work? you must notice that there is some complicated queries in my db. ...

Developing enterprise level application using LINQ

Using LINQ to SQL make application development faster but dissolves the logical layers in the application. The data access layer and the business objects layers almost have no identity, they sit in the same dll. Does any one has an idea on how to develop an enterprise level application using LINQ to SQL. How do we cleanly separate the bu...

Linq to SQL and SQL Server Compact Error: "There was an error parsing the query."

I created a SQL server compact database (MyDatabase.sdf), and populated it with some data. I then ran SQLMetal.exe and generated a linq to sql class (MyDatabase.mdf) Now I'm trying to select all records from a table with a relatively straightforward select, and I get the error: "There was an error parsing the query. [ Token line nu...

Linq to SQL: How to delete using only the primary key?

How do I delete a record using Linq to SQL using only the primary key, without having to retrieve the exsting record from the database? ...

How do I open a Windows Form returning only data from specific id

I have a C# windows application which does the following: 1) the main form is called EmployeeForm.cs which holds 1 employee record from a sql database. I have used linq to sql to display the records. 2) There is a button on the EmployeeForm when clicked opens another form called Orders.cs which displays a datagrid of orders pertaining...

Query only the first detail record for each master record

If I have the following master-detail relationship: owner_tbl auto_tbl --------- -------- owner ---> owner auto year And I have the following table data: owner_tbl auto_tbl --------- -------- john john, corvette, 1968 john, prius, 2008 james james, f-150,...

Hard to update an Entity created by another LINQ to SQL context.

Why this keep bugging me all day. I have an entity with several references where i get from a context which I then Dispose. Do some Changes and try to SubmitChanges(). While calling SubmitChanges() without .Attach() seems to simply do nothing. When using .Attach() I get the Exception : An attempt has been made to Attach or Add an enti...

Dynamic Data: how to filter dropdown for foreign key on edit page

Using Linq-to-SQL and Dynamic Data. On a Dynamic Data edit screen, a dropdown lists the possible values for a foreign key. I need to filter the values listed in this dropdown, preferably by adding a where clause on the linq-to-sql query. Any ideas? ...

Ensure LINQ to SQL Entities Delete On Submit.

What is the best way to mark some entities DeleteOnSubmit(). Is there a way to check and say to the context that this is for deletion? Example: I have an Entity which reference an EntitySet<> and i delete from the EntitySet<> 4 of the 8 entities. When submitting changes i want to say DeleteOnSubmit() on those 4! This scenario should pla...