Inserting record into sql from a struct via linq?

In LINQ2SQL you first need to add your table to the LINQ/DBML designer, then you can use it in code like this using (var context = new MyDataContext()) { var pm = new Product_Master(); // Type generated by the LINQ designer. Pm. Property1 = "foo"; pm.

Property2 = 123; //... context. Product_Master. InsertOnSubmit(pm); context.SubmitChanges(); } You need to map your fields from the struct manually to the properties of the Product_Master object.

When debugging it appears that the fields are being mapped however the data isn't being saved to the table. Any ideas what I might be doing wrong or do you think this maybe the issue Jim Bolla is speaking of? – JRB Mar 23 at 17:05.

There might be issues with structs being passed since LINQ normally updates the property in your object that corresponds to the identity column in your table. This might not work with a struct object being passed by value. I've never tried it but I don't think I'd even try just because of the potential complications.

Jim, I maybe in fact having the problem you are speaking of. The data isn't being saved into the table. If I am understanding you post you are saying that linq is not the best way to insert the data.

If not a problem, could you suggest a more reliable solution? Thanks – JRB Mar 23 at 17:10 My preferred method of using LINQ to SQL is to use SqlMetal to generate classes for me that can be used to interact with the DB. The key advantage to this is that every time I rerun SqlMetal, any schema changes are applied.

Most breaking changes will show up as compile time errors. – Jim Bolla Mar 25 at 15:58 Thank you Jim, I will read up on it. – JRB Apr 4 at 11:54.

Goal: In C#, to take a struct and insert data to a sql table named Product_Master via linq to sql - Or any other solution that is most efficient. I am using a web service that returns the response in the form of a struct (product_ID, DateTime, Description). The name of the struct is productOutput.

What might be the most efficient way to accomplish this. In another part of the project I have been using linq to sql to query the table so in trying to keep consistency I have been trying to use linq, without success. I am interested in the best way so if linq isn’t the best way I am open to any solution.

Note: I am new to c# so the more details the better.

In LINQ2SQL you first need to add your table to the LINQ/DBML designer, then you can use it in code like this.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions