linq-to-sql

database independent Silverlight application - possible ?

I am developing my application in Silverlight with MVVM pattern support. Now I use Sql server 2008, but I am start thinking about in future use also Oracle and XML as storage for my data. I query with linq to sql. It is pattern which I can use to completely automated and independent from database my application? Where I will only replac...

Are there any linq-to-sql for Databases other than MS-SQL?

Hey =) I am wondering if it is possible to use Linq functionality to connect to a database like my-sql If it is possible are you able to use the designer to created the DataAccessLayer like with MS-SQL or do you have to hand code its content. Thanks in advance. KJ ...

Help rewriting existing TSQL query with "Not Exists" clause into LINQ

I'm having trouble translating an existing TSQL query with a "Not Exist" clause into working LINQ for use in an ASP.NET MVC app. Here's my existing query. SELECT OrgID, ContentID, FriendlyTitle FROM ContentRollup CR WHERE OrgID = @sOrgID OR ( OrgID = '*' AND NOT EXISTS ( SELECT ...

Create link on page w/ web address stored in database

This seems like it should be easy, but I can't seem to figure it out. All of my google searches lead me to linking to databases which isn't what I want to do. I'm a complete web development newb. I've roughly followed the NerdDinner tutorial in creating my web app. One of my stored fields is a web address. On the Index and Details p...

Should I create multiple LINQ to SQL Classes Contexts in my projects.

This is a design question, I noticed that by time by LINQ-to-SQL Context gets crowded with all the tables from the database, so today I wanted to create a new context for the new tables I added recently. The tables makes up a unit of logic by themselves and they are separated from other tables logically, except for 2 tables. I am plannin...

What's faster? Struct array or DataTable

I am using LinqToSQL to process data from SQL Server to dump it into an iSeries server for further processing. More details on that here. My problem is that it is taking about 1.25 minutes to process those 350 rows of data. I am still trying to decipher the results from the SQL Server Profiler, but there are a TON of queries being run. ...

Why doesn't my linq to sql generated classes have OnCreated()

Hi, I've been reading over the internet about a partial method that I can use called OnCreated() to run some logic against my Linq - SQL class while it is being created. How ever there is no partial class by that name for me to use. I'm sure I'm missing something small here. Here is what I'm trying to call in the partial class partial...

Linq Asp.net code optimization

I'm using AdventureWorks as a database to get familiar with linq and asp.net interface and was wondering if anyone could take a look at my code behind in C# and give me a optimized way to get the results populated when searched and then updated when submitted. protected void btnSearch_Click(object sender, EventArgs e) { Test...

Display list of values separated by commas without trailing comma

I have an ASP.Net-MVC app using LinqToSql. I have a subcontracts table, a service_lines table and a mapping/link table Service_lineToSubcontracts which contains the subcontract_id and service_line_id. On the subcontract view, I'd like to list the corresponding service lines. This works, but has a trailing comma. <% foreach (var sls i...

Debugging a tough LINQ-to-SQL Timeout

I'm getting a timeout error when trying to execute a LINQ (-to-SQL) query System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Now, this is not just a case of a slow query: I run the equivalent SQL in SQL Management Studio and it com...

Automatic LINQ to SQL entities validation

Is there anyway to make LINQ entities validate automatically according to the properties of the datatypes defined in the database? For example, if my property maps to a varchar(40) not null in the database, automatically validate the property to be not null and 40 length? ...

How to manipulate values in LINQ query without "Explicit construction of entity type ### in query is not allowed when trying to modify value" error

Is it possible to change a field value from inside a LINQ select query for use in an ASP.NET MVC app? For example, if a query returns a field with value "foo," I want it's output to be "bar" instead. Essentially, I want LINQ to create this TSQL statement: CREATE PROCEDURE GetSpecialCaseOfMyObject ( @param varchar(10) ) AS S...

LINQ to SQL - Custom Object with List<T> Property

Hello there, What I am attempting to do is the following: I have a custom object OTest and OSubTest: public class OTest { public int TestId {get; set;} public List<OSubTest> SubTests {get; set;} } public class OSubTest { public int SubTestId {get; set;} } Now, I will run a LINQ to SQL query which will look like this: var ...

Many to Many LINQ TO SQL Query

I have the following tables: Users Roles UserRoles MenuItems RoleMenuItems A User can have multiple Roles and a MenuItem can be accessed by multiple Roles. Now I want to write a method as follows: public IList<MenuItems> GetMenuItems(UserRoles userRoles) { var menus = // LINQ query to get the MenuItems by UserRoles return menu...

Why would you create your own XML mapping file for Linq to SQL instead of using the dbml

I see a number of posts talk about rolling your own LINQ to SQL XML mapping file. Why would you do this instead of using SQLMetal or the designer built into studio? Is it because you want to work with your own POCOs? ...

LinqToSQL + paging + dynamic sort???

I have a problem on using LinqToSQL with paging + dynamic sorting. These are my sample code. Using db As New MyDataContext(connectionString) db.Log = new DebuggerWritter Dim result = db.User.OrderBy(Function(u) u.UserId) result = result.Skip((pageNo - 1) * pageSize).Take(pageSize) End Using This is the SQL scr...

Linq to SQL one:one relationship not setting child's PK to parent's identity value

Hey, I have two tables: ScheduledEvent and DrawSequence. The ScheduledEvent table has zero or one DrawSequence entries. The PK of the ScheduledEvent is an identity integer which is used in a FK from DrawSequence. I have created by dbml file, generated the classes and it shows the parent (ScheduledEvent) has an EntitytRef to the child (D...

How to force recompile of execution path of a Linq to SQL query?

I have a LINQ to SQL query that's created dynamically. Funny thing is, when I run it in SQL Management Studio it's lightning fast. When I run it from L2S it becomes awefully slow after a while. This is probably because of the query plan/execution path. When I restart SQL Server the L2S query is also lightning fast again. Now with T-SQL...

Saving LINQ-to-SQL Transactions to Re-Run Later?

Hi Guys I wrote a an application for configuring a platform we have. Our current process is make the configuration changes in a staging environment and when they're approved, make the same changes in a production environment. There's room for error in this process in that there's a risk that the user might mistakenly make a change in ...

LINQ to SQL select all fields in table but with distict column

I need to return a list of counties, but I need to filter out duplicate phone code values. For some reason I'm having trouble with the syntax, can anyone show me how to do this? Should I be using the group by instead? ...