linq-to-sql

In LINQ : select from table witch not known , and not exist in DBML

I wanna use DataContext.ExecuteQuery<> with TSql "Select * From ... " whatever , and fetch all the fields of each table that dosn't exist on DBML. DataContext.ExecuteQuery< What should I use HERE !!!> ...

ASP.NET MVC / Linq-to-SQL classes: Can I get it to infer readable display names?

If I have a table Orders with fields CustomerID, OrderID and OrderDate, then the "Linq-to-SQL classes" generated class will be called Orders, with members called CustomerID, OrderID and OrderDate. So far so good. However, if I then do Html.LabelFor(m => m.OrderDate) then the generated text will be "OrderDate" instead of "Order Date". I...

Use the same linq with different table prefixes

Hi, I have a webapplication that uses LINQ to connect to a database. The problem is that I Only have 1 database, and I need a several copy's of the tables, 1 copy / client. Is it possible to make linq use a set of tables acording to their prefex ? ...

How do I save an object that contains and EntitySet?

Say I have an User (mapped to a User table) and the Edit view (in MVC) displays a multiselectlist of Modules (mapped to a Modules table) that user can access, with the Modules pre-selected based on the User's EntitySet of Modules. I have tried saving the User then deleting all User_Modules manually and adding them back based on what's s...

LINQ: Convert EntityRef to EntitySet

Hi, I have the following DB structure, which is not something I can change: Product table: IdProduct, Price,....etc Product Description table: IdProductDescrition, IdProduct, IdLiteral,...etc Category Table: IdCategory, IdLiteral Literals Table: idLiteral, idLanguage, literal The Literals table holds the value of literals in seve...

Why don't the classes in the DBML designer appear in alphabetical order?

I have a DBML file with a very large data model. Whenever I need to add a relationship between to tables I have to select the other table from a combo box which appears to be in in almost random order. Is there a reason these dropdowns aren't in alphabetical order, or is there a way to put them in some kind of order? ...

How do you use the LINQ to SQL designer to generate accessor methods for subclasses?

Above is the LINQ to SQL designer view for my data context. Below is the relevant code that the designer generates: Accessor for the abstract ActivityBase class: public System.Data.Linq.Table<ActivityBase> ActivityBases { get { return this.GetTable<ActivityBase>(); ...

Using Linq, how to separate a list in to grouped objects by name?

I have a table where a record looks like this varchar(255) Name varchar(255) Text varchar(255) Value Name is the DDL name, Text is what is displayed, and Value is returned upon selection. There are between one and twenty options for each Name. Without iterating though each option like a cursor, is there any way to pull out a li...

How can we handle concurrency errors in LINQ to SQL?

How can we handle concurrency errors in LINQ to SQL? ...

OneToMany relationship appearing as OneToOne in Linq to SQL diagram

I have a OneToMany relationship in an SQL Server database. When I add the tables to my Linq to SQL diagram (DBML) the relationship comes up as OneToOne. I have other OneToMany relationships which synchronise correctly. Even If I change the cardinality to OneToMany the collection still only returns a single entity. Could this be a bug...

How to update single object in sql to linq

For example a = datacontext.customers.FirstOrDefaul(); b = datacontext.customers.Skip(1).FirstOrDefaul(); a.name="name1"; b.Name="name2"; When i call datacontext.SubmitChanges(), Two object updated. I don't want this. I need only Update a object. How do it? EDIT WPFWindow windowA=new WPFWINDOW() windowA.DataContext=a; windowA.Sh...

DynamicQuery: How to select a column with linq query that takes parameters

Hello, We want to set up a directory of all the organizations working with us. They are incredibly diverse (government, embassy, private companies, and organizations depending on them ). So, I've resolved to create 2 tables. Table 1 will treat all the organizations equally, i.e. it'll collect all the basic information (name, address, ph...

How to eager load sibling data using LINQ to SQL?

The goal is to issue the fewest queries to SQL Server using LINQ to SQL without using anonymous types. The return type for the method will need to be IList<Child1>. The relationships are as follows: Parent Child1 Child2 Grandchild1 Parent > Child1 is a one-to-many relationship Child1 > Grandchild1 is a one-to...

Linq2Sql loading associated model in a new instance.

Hi all I have a collection of new instances of a linq2SQL object. They were created by the default MVC 2.0 model binder. The created instances include a foreign key to an associated model. The created instance does not include an instance of the associated model. I'd like to populate the associated model based on the foreign key. What is...

ASP.NET MVC 2: Updating a Linq-To-Sql Entity with an EntitySet

I have a Linq to Sql Entity which has an EntitySet. In my View I display the Entity with it's properties plus an editable list for the child entites. The user can dynamically add and delete those child entities. The DefaultModelBinder works fine so far, it correctly binds the child entites. Now my problem is that I just can't get Linq T...

How to use Generic in LINQ to SQL Fetch Operation ?

I am using LINQ to SQL for my data retrieval. One common fetching scenario is to or fetch by some criteria. The code is below. public EmployeeRegistrationView FetchByEmailID(IDictionary<string, string> criteria) { var selEmployeeRegistrationView = from P in db.EmployeeRegistrationViews ...

linq-to-sql combine child expressions

I need to create and combine several expressions for child entity into one to use it on "Any" operator of a parent. Code now looks like this: Expresion<Child, bool> startDateExpression; if(String.IsNullOrEmpty(startDate) startDateExpression = t => true; else startDateExpression = t => t.start_date >= startDate; Expression<Ch...

linq: SQL performance on high loaded web applications

I started working with linq to SQL several weeks ago. I got really tired of working with SQL server directly through the SQL queries (sqldatareader, sqlcommand and all this good stuff).  After hearing about linq to SQL and mvc I quickly moved all my projects to these technologies. I expected linq to SQL work slower but it suprisongly tu...

Linq-to-SQL- A stored procedure returns field which is not there in Mapped Table Info

We are using Linq-to-SQL with stored Procedures we need help on one of our problem. We are having user tables which is having all field required for user table like firstname,lastname and other fields that table is also there in our DBML files.Now the problem is that we are having a stored procedure that is mapped to table->User returnin...

sql and linq query

Database has tables Photos and PhotoAlbums. I need a query that will select all albums and only one photo from each album. I need SQL and LINQ version of this query. Thanks in advance. ...