Is there any reason something like this would not work?
This is the logic I have used many times to update a record in a table with LINQ
DataClasses1DataContext db = new DataClasses1DataContext();
User updateUser = db.Users.Single(e => e.user == user);
updateUser.InUse = !updateUser.InUse;
db.Log = new System.IO.StreamWriter(@"c:\t...
Hello,
I ran into an interesting problem while using DLINQ. When I instantiate an entity, calling .SubmitChanges() on the DataContext will insert a new row into the database - without having ever called .Insert[All]OnSubmit(...).
//Code sample:
Data.NetServices _netServices = new Data.NetServices(_connString);
Data.ProductOption[] te...
I have just deployed my first application in .NET MVC and i'm having issues.
I have resolved the iis 5.1 problems with the routing (If anyone is looking for this go here:
http://itscommonsensestupid.blogspot.com/2008/11/deploy-aspnet-mvc-app-on-windows-xp-iis.html )
**Now my issue is that wherever I call db.SubmitChanges() on my data ...
I'm using Linq to SQL. I have a DataContext against which I am .SubmitChanges()'ing. There is an error inserting the identity field, and I'd like to see the query it's using to insert this identity field.
I don't see the query itself within the quickwatch; where can I find it from within the debugger?
...
I'm going through an XML file of articles and the journalist(s) that wrote them. As we are adding the articles into _Data our datacontext we may come across a journalist that needs adding so we do this:
newJourno = New journalist With {.name = strJournalist}
_Data.journalists.InsertOnSubmit(newJourno)
.articles_journalists.Add(New artic...
I am running the code to get the change set just before a linq submit changes call.
private void OnSubmitHandleReplication()
{
System.Data.Linq.ChangeSet changes = GetChangeSet();
//Do something with change set
}
In the do something section I need to know what order things were submitted in, and what order they will post to th...
I am using Sql tables without rowversion or timestamp. However, I need to use Linq to update certain values in the table. Since Linq cannot know which values to update, I am using a second DataContext to retrieve the current object from database and use both the database and the actual object as Input for the Attach method like so:
Publ...
I am using LINQ to insert records in the database. I create these records and keep track of them using a List. Based on some logic, I delete some of the records by deleting from the List. (I am using the same DataContext object).
When I want to insert the records in the database, I do the corresponding linq table's InsertOnSubmit() fol...
Using LINQ-to-SQL, I would like to automatically create child records when inserting the parent entity. Basically, mimicking how an SQL Insert trigger would work, but in-code so that some additional processing can be done.
The parent has an association to the child, but it seems that I cannot simply add new child records during the Dat...
Apologies up front, because this isn't a question but a solution - but it took a lot of searching to find out the answer and google wasn't much help, so I wanted to give something back to the community by providing the error and the solution to help future googlers.
When using LINQ to SQL, I ran into a problem when submitting changes (t...
How do you verify that SubmitChanges() worked for inserts and updates? The method doesn't return a bool or int value.
...
Hi. I think a lot of people have had this issue but I'm not able to fix it or understand why I'm having it. I've been tearing hair out for a couple of hours now.
I'm getting the error, "Object reference not set to an instance of an object." on my datacontext.SubmitChanges() on the SECOND time this method runs (I'm looping through a ...
I've set up a very simple example with LINQ-TO-SQL in WPF.
I can get an object (pageItem) out like this and I can change the property and when I call SubmitChanges() it gives me no error but it doesn't save the change.
MainDataContext db = new MainDataContext();
var pageItem = (from p in db.PageItems
where p.Id == 1
...
I've got a Silverlight app using RIA services and LINQ2SQL and have objects in my Silverlight app.
I query all the records in a table (via a LINQ query, using a datacontext) in the Silverlight app and create a user control for each object (record) and put that object into the control because I need the information later. Then later,...
Hi,
I'm experiencing a strange behavior that I really don't know how to work around it. I'm trying to read an entity just after it has been inserted (right after the ExecuteDynamicInsert) and when the partial method returns, I always get a System.Data.Linq.DuplicateKeyException "The database generated a key that is already in use.".
H...
Hello everyone,
I'm really a LINQ newbie. I got an unknown problem:
public static int save(TEntity obj)
{
var table = dbo.GetTable<TEntity>();
var mapping = dbo.Mapping.GetTable(typeof(TEntity));
var pkfield = mapping.RowType.DataMembers.Where(d => d.IsPrimaryKey).Take(1).SingleOrDefault();
if (Conve...
I've been battling this for a while. I'm trying to implement a many to one association. I have a bunch of rows in a table, called readings. These accumulate over time, and every now and then I want to export them. When I export them I want to create a new object called ExportEvent, to track which rows were exported, so they can be re-exp...
I have a mapping table like:
Article_to_Categories
ArticleID
CategoryID
How would I insert into this table using linq2sql?
...
So at the root of my DB, I have a table "Customer." Customer has foreign keys going to about 6-7 other tables such as Receipts, Addresses, Documents etc. If I were to delete a customer using SubmitChanges(), would that seek out all those records with the foreign key association and delete them too, or would I need to do like 6 queries?
...
The ASP.NET linq SubmitChanges method commits changes for all previous database modifications since the last time it was called.
I have a case where I do something like the following:
ClassX x = new Abc.Linq.ClassX();
DataContext.InsertOnSubmit(x);
ClassY y = new Abc.Linq.ClassXY();
DataContext.InsertOnSubmit(y);
DataContext.SubmitCh...