linq-to-sql

linq to sql not counting all columns

I have a table called Game, which holds 4 columns for player id's. And I also have a table called Player. When I try to count all the games in which a player has been in, I only get the players from the first column in the Game table. player.Games.Count(); I have set up foreign keys for all the tables, and it's showing up correctly in...

Add entity to EntitySet throw exception on submitchanges()

Hello I'm using Linq to Sql and have a Many-To-Many relation and therefore use a relation table. When i try to insert data with relation/association i get error. I use manual schema creation. My simplified code: First table/class Booklet has this association: private EntitySet<BookletChapterRel> _bookletChapterRel = new EntityS...

Converting a "DBML" file to a "SQL database file"

I have the DBML file of a database and would like to generate an SQL database file from this file. Thanks ...

LINQ to SQL doesn't call DELETE

I am deleting a bunch of records from different tables that are linked with foreign keys. When I call 'SubmitChanges' the following error is received: The DELETE statement conflicted with the REFERENCE constraint FK_PTXProductMap_CustomerProduct". The conflict occurred in database "SOTI", table "dbo.PTXProductMap", column 'Inst...

LINQ and TranscationScope not working

I am using LINQ select statement wrapped in a TransactionScope (to change the locking) but according to SQL Profiler, it doesn't seem to be working. My code looks like: using (var ts = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted} )) { using (myDBDataCo...

LINQ to SQL group by with take

I have a table that looks like this: Id GroupId Value and it has about 100 rows How can I return the top 10 rows for value but with no duplicating GroupId? ...

Working with MVC 2.0 and the Model in a separate assembly

Hi, I'm new to MVC and even though there is a lot (and I do mean a lot) of information out there that is very useful - it's proofing very difficult to get a clear understanding on how to achieve my exact requirements with MVC 2.0. I would like to set up a solution as follows: Provide a web UI using an MVC 2.0 project. Use Linq to SQL ...

Linq to sql - left outer Join

I have Three Table without assosiatated as Follows Clients Bank Country Some clients they don't Have bank Details so I need to get all the Cleint Info Who has the bank and Who hasn't the bank, and same as country info I know It's "left outer join" method. how its in the Linq to sql vb.net code Please ...

how to use sql with LINQ

Hi, I have the asp.net web application in C# language with framework 3.5. I have also sql server database . I want to use sql to Linq concept for insert, update, delete and select the records as well as maintain the transaction like commit and rollback . How to achieve this ? ...

LINQ to SQL handling nulls

Hi, What is the best way to deal with null values in Linq. I have this code which retrieves the customer contacts from the db but if the contact details don't exist it creates a new instance void SetProperty(int _CustomerID) { Contacts_GetResult Contact; if (Global.VariableStore._Contact == null) { Contact = Cd.Con...

LINQ to SQL seems to be slowing application

Hi all i seem to be having an issue with LINQ, i am currently maintaining an in house Intranet application at work,When Saving logs it seems to slow down now,upon debugging i have came to realise that every time it saves a log the application pauses at these two section lines of codes.It does save the logs ,just that its slow and at time...

How do I convert an Enum to an Int for use in an Expression.Equals operation?

I am trying to dynamically build an expression tree in C#, which is compiled and used as the predicate for LINQ-to-SQL Where() call. The problem is that I am trying to compare an Enum (with int as its underlying type) directly against an Int, but this is failing with the error "The member MyEnumType has no supported translation to SQL". ...

How do I update a foreign key efficiently in LINQ to SQL/SQLMetal?

I ran into an issue trying to update a foreign key field: record.ForeignId = newId; It bombs with "Operation is not valid due to the current state of the object" due to SQLMetal code that throws System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException(). I was not the first to hit this issue: http://stackoverflow.com/questions/2...

full text index + joins + linq : how to do this properly?

SO really there are two parts of the question: 1) how to use CONTAINSTABLE() with bunch of inner joins? Suppose there are two tables: Item (ItemID, CategoryID, Name) Category (CategoryID, ParentCategoryID, Name) using "dumb" like search this looks like this: create view [db].[vItem] as select i.*, c1.Name as SubCategory, c2.Name as...

Simple search with Linq To SQL

What is the problem with this query and how can I fix it? public JsonResult Find(string q) { var k = new List<string>(q.Split(' ')); return Json(_dataContext.Jobs .OrderBy(p => new List<string>(p.Keywords.Split(' ')).Where(n => k.Contains(n)).Count()) .Select(p => new { p.Title, p.IsFullTime, p.Location, p.Categ...

ASP.NET MVC: How can I serialized data from instance of classes generated by Linq2Sql?

Hello, I've learned to create multi-steps application from the Steve Sanderson's book (Pro ASP.Net MVC/APress p.477). Since then, I've adapted that Technique to many scenarios. Basically, it's about serialization/deserialization to keep data live between requests. But the only problem is I cannot use model generated by Linq2Sql becaus...

Object persistence in .NET and SQL Server, with incomplete values

I am building a form in Net framework 4.0 using linq to sql , and had a question about object persistence. I have a case where a user is asked to fill out a very long form several pages in length. Since it is so long, there is a need to SAVE the data midstream. Session level persistence is not an option, since they could SAVE the form...

Mocking LINQ To SQL data provider, NotSupportedException on Live code

Yet another "simple" question about unit testing model objects that uses data access layer. When I mock my Table<Customer> to IQuerable<ICustomer>, where new List<FakeCustomer>().AsQuerable() is used in role of in memory data store, the following code passes unit test perfectly: var filteredCustomers = from c in dal.Customers ...

LINQ to SQL Invalid Cast Issue

Hello All, I'm getting an invalid cast exception but I'm not sure why, here is the list of my conversions. SQL -> VB.NET char(4) -> String varchar(50) -> String tinyint -> Integer char(1) -> Char bit -> boolean smallint -> Integer smallmoney -> Double int -> Integer datetime -> datetime Thanks in advance for your help ...

LINQ to SQL SubmitChanges() Inserts two Database Rows and one Child Row.

I have this going me crazy, I'm attaching a List with 1 Customer and 1 Address child record row. Everything seems OK while debugging. 1 customer Row and 1 Address Row should inserted. But instead I get 2 Customer Records and 1 Address Row. I don't know why. When Attaching and looping inside the List only 1 record seen. Any points? [E...