linq-to-sql

Conditional where with or criteria linqtosql

Howdy, I've figured out how to do conditional queries with linq to sql and I've also figured out how to OR where clauses. Unfortunately I can't figure out how to do both at once. I can do a conditional where clause something like: var ResultsFromProfiles = from AllPeeps in SearchDC.aspnet_Users select AllPeeps...

linq - inserting new data replaces existing data on database.why?

Hello everyone, When I call the datacontextInstance.Insertonsubmit() and datacontextinstance.submitChanges(), it clears all the existing data in the database before inserting the new data. How do I perform a real insert operation? I want to add new data to the existing table without clearing out the existing data. Thanks Edit: Here...

Get table-data from table-name in LINQ DataContext

I need to get table data from table name from Linq DataContext. Instead of this var results = db.Authors; I need to do something like this. string tableName = "Authors"; var results = db[tableName]; It could be any table name that is available in DataContext. ...

Can NHibernate, Subsonic or L2S do Per-Entity Auto-Increment?

I have a SQL Server 2008 database with a composite key: ProjectID (GUID) and TaskID (int). ProjectID is a foreign key to a Projects table. I want to have TaskID Auto-Increment, but restart for every ProjectID (that is: every projectID should have 1,2,3,... as TaskID). To my knowledge, this is not possible in SQL Server out of the box, a...

Why would Entity Framework not be able to use ToString() in a LINQ statement?

This works in LINQ-to-SQL: var customersTest = from c in db.Customers select new { Id = c.Id, Addresses = from a in db.Addresses where c.Id.ToString() == a.ReferenzId select a }; foreach (var item in customersTest) { Con...

Linq 2 SQL One to Zero or One relationship possible?

Is it possible to create a one to zero or one relationship in Linq2SQL? My understanding is that to create a one to one relationship you create a FK relationship on the PK of each table. But you cannot make the PK nullable, so I don't see how to make a one to zero or one relationship work? I'm using the designer to automatically crea...

Executing LINQ-to-SQL Debug Output?

When you log LINQ-to-SQL's query output via the "Log" property on the DataContext object, you get output similar to: SELECT [t0].[fullaname], [t0].[Worker], [t0].[Office] FROM [dbo].[Workers] AS [t0] WHERE [t0].[OfficeID] = @p0 ORDER BY [t0].[Name] -- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [412] -- Context: SqlProvider(Sql2005) ...

How to blank out a field in an MVC app using TinyMCE

I've got an MVC app that gives the user textarea's to update some description fields. It's strongly-typed to a table object, and the fields are wrapped in a form with a Submit button. Occaisionally they don't want any data in a field, but when they delete the text and try to save, the blanked-out field comes back with its original text ...

Get more returns of a Stored Procedure (Linq to SQL)

Hi everybody. I have a question. Please it´s extremely urgent !! I created a Store Procedure to make tests for study its functionality. my procedure execute two selects: Example: Select TOP 20 * From NotaFiscal Select TOP 20 * From ProdutoNotaFiscal Using the ADO.NET, the Dataset is filled with 2 results and generates 2 DataTables...

Linq to SQL - How should I manage database requests?

I have studied a bit into the lifespan of the DataContext trying to work out what is the best possible way of doing things. Given I want to re-use my DAL in a web application I decided to go with the DataContext Per Business Object Request approach. My idea was to extend my L2S entities from the dbml file to retrieve information the da...

Eager loading / prefetching many-to-many without LoadOptions - Linq to Sql

I've got a situation where I need to prefetch some entities through a many-to-many relationship. So it's like the classic BlogPost <- BlogPostTag -> Tag situation. Yes, I'm aware of LoadOptions but I can't use it because it's a web application and I'm using the one datacontext per request pattern. It also seems you can't use projection...

Linq to SQL EntitySet Binding the MVVM way

Hi everybody! In a WPF application i'm using LINQ to SQL classes (created by SQL Metal, thus implementing POCOs). Let's assume i have a table User and a Table Pictures. These pictures are actually created from one picture, the difference between them may be the size, coloring,... So every user may has more than one Pictures, so the a...

Problem when accessing another page while first page is processing a file

I have a web app which processes files and writes the data to a database. This process can take up to 2 minutes. Let's say this is done on ProcessFile.aspx. I wanted to ensure data integrity so I wrapped all the database processing in a TransactionScope. The problem occurs when I am processing a file and then try to access another page ...

More efficient Linq-to-SQL query

I am looking for a more efficient way to do this...(see below)... I have to perform it seven times as I have seven feature articles. The id I am feeding off is the page id (aka featurearticles.fk_pageID_item1 featurearticles.fk_pageID_item2). I am ok with doing a table join and not selecting * as it were. I am also ok with making a temp...

LINQ: Getting the row with the maximum value of a given attribute

I have a bunch of rows grouped on an attribute called MyID. Now I want the one row from each group where the StatusDate attribute is the highest in that one group. This is what I've come up with. rows.Select(x => x.Where(y => y.StatusDate == x.Max(z => z.StatusDate)).First()) With a bit more explanation: rows.Select(x => // x is a g...

Linq to SQL EntitySet Records causing duplicate insertion

In a WPF application i'm using Linq to SQL in a multi tier application. (This is an archailogy photo filing application), so every excavation has its corresponding Pictures, thus a one-to-many relationship. This relationship is correctly created by SQLMetal (which i'm using to create the POCOs). So here is the situation i 'm having tro...

linqdatasource: Databind from another project

I have a solution "Foo" with 2 projects. "FooCore" and "FooWeb" where FooCore peoject contains the FooDatacontext in namespace Foo.FooCore.Core.Domain . How can bind the datacontext with linqdatasource in FooWeb project in aspx page. Is this possible by doing "<% Import Namespace="Foo.FooCore.Core.Domain"%>" in that aspx page? I hope I a...

Linq query with multiple Sums, Groupings and Joins

I have an SQL query which I need to translate to Linq to SQL. I was successful until it came to Sums and I'm completely stuck there. I know how to do single/simple groupings and sums but this time I desperately need help. I'd appreciate any ideas. Table relations are like this: TreeNodes - one-to-many - Dispatches (not every TreeNode h...

Dynamic built Linq to SQL Query

Hi, i want to build a generic search window using linq to sql. This is what i was trying to do: class SearchWindow<T> : Form : Where T: class { public SearchWindow(Func<T, string> codeSelector, Func<T, string> nameSelector) { var db = new DataContext(); var table = db.GetTable<T>(); ...

return non-duplication of records in result with linq

How i can return non-duplication of records in result with linq? var design = firoozehDataContext.Designs; comboBoxCode.DataSource = design.ToList(); above code return all records, but i want to do that i said on above. thanks ...