linq-to-sql

XMl Serialization of Linq-to-Sql objects?

I am working on an Audit Log for an application that uses Linq-To-Sql. I want to serialise an object to stores its values in a XML column in a SQL Server databse. My problem is that when I try to serialize a Linq-To-Sql obejct that it attempts to serialize all associated entities and entity sets. My first attempt at a solution was t...

Problem in LINQtoSQL with dual schema in Database

I have two tables, both named as say, Employee in two different schema HR and Production [i.e. dbo.HR.Employee and dbo.Production.Employee are my two database objects]. While dragging these two tables in LINQ to SQL design pane its generating two classes named Employee and Employee1. My ques: Is there any way I can create classes with Da...

Dynamic Data | LINQ TO SQL | General Validation

I have 5 different entities for which dynamic data(with LINQTOSQL) was generated. On Insert(Insert.aspx) of any of these entities, if there is an error, I would like to notify user that error happened and possibly show some generic error message. 1) I am not talking about regular required field errors but something like "Unique constra...

Linq to SQL Compact - Update binding

When I set the ItemsSource of a ListBox to the contents of a table, like this: this.listBox.ItemsSource = db.Table; The items are not updated automatically in the ListBox. How can I manage to update the ListBox automatically when items are added, removed or changed? And can I also receive an event when the collection has changed? ...

What is the correct way of reading single line of data by using Linq to SQL?

I'm very new to Linq, I can find multi-line data reading examples everywhere (by using foreach()), but what is the correct way of reading a single line of data? Like a classic Product Detail page. Below is what I tried: var q = from c in db.Products where c.ProductId == ProductId select new { c.ProductName, c.ProductDescription...

How do I properly filter child objects?

I apologize for syntax errors, this is my simple explanation of the problem. I've setup my dbml file with a relationship between Customers and Orders on CustomerId. I'm trying to return all orders for a customer that are less than $10. Customer customer = context.Customers.FirstOrDefault(c => c.Id == 123); IEnumerable<Order> orders = c...

Linq data update

Can we update a record using Table.Attach() in LINQ to SQL? If yes, how? The idea is, I shall create a new object, attach it to the Table (which in turn will be attached to DataContext), then I shall submit changes, etc. It ID matches, the existing object will be updated. ...

counting items in grouped results in Linq to Sql

I want to group results of query by the item id and count number of items in each group. finally i will take only one item from each group and the count of that group to display results.GroupBy(r=>r.ID).... ...

Linq to SQL Int16 Gets Converted as Int32 In SQL Command

With the method parameter Int16? id And the Linq to SQL where clause where !id.HasValue || m.Id == id The resulting command text for the condition in the data context is From the visualizer: SELECT [t0].[Id], [t0].[Name], [t0].[IsActive] FROM [Model] AS [t0] WHERE (CONVERT(Int,[t0].[Id])) = @p0 ------------------------------- @p0...

Weird problem with my Linq to Sql query and manually adding some JOIN statements.

Hi folks, my Linq To Sql model contains some entites that cause the generated Sql code to be LEFT OUTER JOINS. this is correct, because of how the tables are modelled. BUT, for a particular query, I actually know the results will always exist in the child table. As such, I was hoping to change the SQL from a LEFT OUTER JOIN to an INNER...

LINQ use with XML

Hi! We have a project in which access the DB layer (MS SQL) with LINQ. Can we now change our DB layer to XML file and still access it with the same LINQ? We want add possibility to store data in a single XML file or a set of XML files. Current LINQ to SQL code looks like: result = (from e in db.Organizations where e.Id == id...

How to recover from System.Data.Linq.DuplicateKeyException without disposing DataContext?

By design I'm expecting a DuplicateKeyExeception from time to time. Is it possible to recover from such situation without recreating the Datacontext? Ideally I would like to remove all records that have duplicated key. ...

Linq 2 SQL , insert Objects with associated child objects List into database , Silverlight RIA

Hi there. I am doing small Silverlight app which will allow users to Create orders. I have created Linq 2 SQL dbml and dragged there my database tables, "Orders" and "OrderLines" , there is an association between them. Order.ID ~ OrderLine.OrderID, so then i created DomainService for my tables, where i enabled client access, it generated...

Multiple SubmitChanges and transaction rollback using Linq To SQL

I'm using TransactionScope to submit data in Linq to SQL. My question is, if I use multiple SubmitChanges in the same scope, will all scope roll back in case of an error or just the changes made after the last SubmitChanges? For example: using (TransactionScope trans = new TransactionScope()) { using (dbDataContext db = new dbDataCo...

Generation custom files from dbml file?

Hi, I've been having a look at making changes to the partial classes generated from a DBML file. I was reading into using the sqlmetal.exe tool but it appears that you can't do much customisation of what it actually spits out. I'm wanting to make changes to the file for serialization purposes, I'd like to add the Data Member Attribute...

How can I make a generic IQueryable in Linq?

Hi everyone!! I'm working in a ASP.NET MVC project and I have this particular situation: I have 3 pages - Product, Order, User. And in each of these pages I have a link calling the same ActionResult differing only by the argument passed depending on the page I'm in. For example: public ActionResult(string typeOfPage) { if (typeOfPag...

Help with linq query with subqueries

Hi there, can anyone help?, i am stuck with a linq query.. basically i have a standard linq query that returns fields, 1 field (insurances) is actually another linq query like so // original from this in etc not included to keep msg short> select new Models.Custom.House.Insurance() { Id = v.IdH...

Find linq Entity through a string value

Hi! How can I receive a string value, for example, "User" and find a Entity with this name, and use this Entity as a type? Thanks!! EDITED: "User" is the name of the Entity in dbml, not a property ...

Help with writing a linq query

Hi there, can anyone help me write a linq query, its a bit confusing... Basically i have a variable which numeberOfDays in my code which for this example is 8 I have a table that lists this. DayFrom DayTo Price 1 3 20 4 5 30 6 8 40 8 25 150 I need to return fr...

How can I convert string to TEntity and use this TEntity object?

Hi! How can I receive a string value, find an Entity with the same name and use this Entity as a type? Thanks!! ...