linq-to-sql

Specifying structure of serialized XML using DataContractSerializer

I am creating serialized XML for a LINQ to SQL project using the DataContractSerializer class. Upon serialization and inspecting the returned object, I get XML that looks like this. - <ContentObject xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/MyProject.Data.Model"&gt; <_x003C_ID_...

Case insensitive string compare in LINQ-to-SQL

I've read that it's unwise to use ToUpper and ToLower to perform case-insensitive string comparisons, but I see no alternative when it comes to LINQ-to-SQL. The ignoreCase and CompareOptions arguments of String.Compare are ignored by LINQ-to-SQL (if you're using a case-sensitive database, you get a case-sensitive comparison even if you a...

Linq To Sql vb.net help

I have a table and I need to select the record based on an Id. I only want to return the record that has the Max(Date) on a date field. How do I do that? In SQL Server I use this SELECT * FROM dch WHERE EffectiveDate = (SELECT MAX(EffectiveDate) FROM dch WHERE ID = 99) AND ID = 99 How can I do this in Linq. Unfortunately this app is ...

LINQ2SQL: How do I declare a member variable of type var?

I have a class like this public class foo { private void getThread() { var AllThreads = from sc in db.ScreenCycles join s in db.Screens on sc.ScreenID equals s.ScreenID select s; } } I want to make the AllThreads variable a class variable...

Performance Comparision of linq 2sql and Ado.net Entity Framework with stored Procedure?

Hi I am devloping the a asp.net site which will have lots of user online at a time. I am writing very efficient stored procedure for it. Which ORM tool should I use? Ado.net entity framework or linq2sql? Performance is needed as our requirement is to load every page in 4 seconds. ...

LINQ to SQL, how to write a method which checks if a row exists when we have multiple tables

Hi, I'm trying to write a method in C# which can take as parameter a tabletype, column and a columnvalue and check if the got a row with a with value the method looks like: public object GetRecordFromDatabase(Type tabletype, string columnname, string columnvalue) I'm using LINQ to SQL and need to to this in a generic way so I don...

maximum number of parameters in sql query...

I do experiment with LINQ since some time. Typical method to enumerate through a collection and change some of its properties in my code would look like: ATDataContext dc = new ATDataContext(Settings.connection_string); int[] col = ListViewClass.getListViewSelectedPositionTags(listView); try { foreach (var item in col) { ...

LINQ To SQL - Select a constant value

In SQL you can selecta constant value: Select "Constant Text", Column1, Column2 From TableX and each row returned from TableX starts with a column containing the text "Constant Text". Any ideas on how I can do this in LINQ to SQL? If I do the above I get the error message "Range variable name can be inferred only from a simple or qu...

Linq to SQL and concurrency with Rob Conery repository pattern

I have implemented a DAL using Rob Conery's spin on the repository pattern (from the MVC Storefront project) where I map database objects to domain objects using Linq and use Linq to SQL to actually get the data. This is all working wonderfully giving me the full control over the shape of my domain objects that I want, but I have hit a ...

How can I supply a table name at runtime using LINQ to SQL?

I have to use LINQ to SQL and along with it a pure SQL classic query. And this SQL query has the Table from where my data will be generated, but I will not know this Table previously. It will be known in compile time. So how can I make LINQ understand from what Table I want to make the query? ...

How can I return a IQueryable in C# 3.0 without knowing its type?

Hi! I have a method where I execute a query SQL (I'm using Linq to SQL but I have to execute a classic SQL query), but I don't know from which table/Entity this query will be generated. So, I was thinking that as I don't know from what Table the query will be generated from, I don't know the type of my IQueryable, am I right? But I do...

LINQ to SQL, Stored Procedures and the Methods Pane (more like Methods PAIN!)

I'm new to LINQ and am having a small issue. I created a DBML file and dragged all of my tables to the design surface. Now, when I try to drag a stored procedure to the methods pane, Visual Studio thinks a second and then doesn't do anything. My method does not show up in the methods pane. Is some error occurring behind the scenes? If s...

LINQ vs. DataTable.Select - How can I get the same results?

Hi, I'm trying to rewrite a direct (disconnected) DataSet.DataTable.Select to LINQ for a textual search: string search = "ProductNo like '%" + searchpattern + "%' OR ProductName like '%" + searchpattern + "%' OR Description like '%" + searchpattern + "%'"; DataSetProducts.sk_productsRow[] dsp = (DataSetProducts.sk_productsRo...

calling a SP which returns a long select return using LINQ

I am calling a SP using linq and the SP returns a very long string. but when i receive the string its truncated. is there any way to increase the return length in linq? ...

Does nHibernate allow drag and drop automatic class creation like linq to sql?

Just a basic question. Learning Linq to SQL and some nHibernate. I am using the mvc tutorial and they drag and drop tables onto the visual studio designer to create the classes and wire up everything. When I experimented with nHibernate I had to do lots with xml files. Does nHibernate have anything that is "easy" like Linq to SQL o...

Tracing LINQ TO SQL generated queries in ASP.NET MVC

Hello, Quick question on LINQ to SQL generated queries output. I am in a ASP.NET MVC project, Visual Studio 2008, and I am trying what's suggested in MSDN documentation: MyDataContext _dc = new MyDataContext(); _dc.Log = Console.Out; But nothing is being shown on "Output" window (CTRL+Alt+O). Is there is something else I need to co...

Acceessing some aggregate functions in a linq datasource in a GridView

I am working on a traditional WebForms project. In the project I am trying out some Linq datasources with plans to eventually migrate to an MVC architecture. I am still very new to Linq. I have a GridView using a Linq datasource. The entities I am showing has a to many relationship and I would like to get the maximum value of a column i...

Conversion SQL to LINQ

How can the below be converted to LINQ SELECT Q.MaterialID AS MaterialID, Q.ProductID AS ProductID, QB.Quantity AS Quantity, Q.ParameterID AS ParameterID, SUM((Q.ParameterValue * Q.Quantity)/Q.TotalTonnes) AS ParameterValue FROM @Quality Q INNER JOIN @QuantityBreakdown QB ON ((Q.MaterialID = QB.MaterialID) OR (Q.MaterialID IS NUL...

LINQ to SQL Unmapped Property

Is it possible to add a custom property in the designer and have it not bound to a column? I fiddled with the settings a bit settled on making a partial class with the property. Is there a way to show this field in the ORM designer? ...

asp.net mvc 1 to many saving post and upload files

I'm new in asp.net mvc. I'm using Linq to Sql and trying to do everything loosely coupled. I've two tables: News NewsFiles What I'm trying to do is save a news and upload its files at the same time. How can I create a news in conjunction with his files saving it to NewsFiles table? The Linq to Sql model is Ok, it includes the obj...