I am using SQL Server Here, ID is an identity column which is the primary key of the table. Let us start with the insertion of bulk data in our database. We create a Stored Procedure in the database as follows:.
We are using OpenXML to get data and insert into our table. Update the name of the Stored Procedure to some thing meaningful. We update the name to insertTestData. We open Program.
Add the following code to the Main method of the Program class:. You can see that we have neither used db. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 8 years, 2 months ago. Active 4 years, 6 months ago. Viewed k times. Tolist ; li.
Tolist ; and want result which looks like this my code gives error can you please tell how i do this. Amit Bisht Amit Bisht 4, 14 14 gold badges 50 50 silver badges 83 83 bronze badges.
It was designed to bring native data querying to. Simply put: what you're doing is not querying. You should be asking yourself "what tool should I use here" instead of trying to force LINQ to be that tool.
Add a comment. Active Oldest Votes. Kamil Budziewski Kamil Budziewski Read here: stackoverflow. SubmitChanges on each iteration It shouldn't cause problems you will need to commonly re-execute it after every every execution. FirstOrDefault ; s. Want to Cancel? Equals false ;. Ollie Beumkes Ollie Beumkes 1 1 silver badge 17 17 bronze badges.
This doesn't seem to do what the OP is asking, your '. Equals' is just returning a value, it's not updating the value. Also, are you are only picking the first value, but the OP says there are potentially multiple and if there aren't any you'll get null exception. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science.
Stack Gives Back When you update C in Depth to the category C , three things should happen:. LINQ to SQL will handle step 1 for you when you call SubmitChanges , but your classes are responsible for updating the other side of their relationship steps 2 and 3. But, and this is the tricky part, we're going to be instructing each side of the relationship to inform the other side when it's updated.
So, we need to add some additional checks to this method to prevent it from looping:. There are two ways to view this relationship in our classes:. In our Book Catalog application, a book can only belong to a single category, so when we update the book's category, it should get automatically moved from the LINQ category to the C one.
To do this, retrieve both books from the DataContext and set their Category to the C category. Then, call SubmitChanges to persist the changes to the database. Even though only the Book objects were updated, the synchronization code we added caused the Category objects to be updated as well:. Now, let's synchronize the M:1 relationships in our M:M Join tables. Whenever we have a M:M Join table, as we do with BookAuthors , the join table is, of course, just two M:1 relationships, so we can mirror what we did for Book.
We want our Join tables to provide a central location for ensuring both sides of the M:M relationship are kept synchronized.
So, regardless of whether someone updates a Book to have a new author, or if they update an Author to add that person's books - the central class BookAuthor will ensure both sides are synchronized accordingly. In our example, we'll update BookAuthor 's set method for Author just like we updated Book. Category 's set :. We can't see this in action just yet. First, we have to see how to handle the other side of our M:M relationships: the 1:M relationship. Just as we can update a Book 's category and have it automatically synchronize the old and the new Category for us, we should be able to add or remove books from a Category and have them update the Book instances accordingly.
Here's the cool part. And, EntitySet s let you specify delegates to be called whenever an item is added to or removed from its collection. So, create two delegate methods to handle this synchronization:. Then, construct the EntitySet by passing in these two delegate methods.
0コメント