Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > LINQ
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
LINQ Discuss Microsoft's LINQ (Language INtegrated Query) for .NET 3.0 and later.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the LINQ section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 17th, 2009, 04:22 PM
Registered User
 
Join Date: Apr 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Linq to Sql - Retrieving the value of an identity column BEFORE inserting new row

Hello, I'm wondering if there is a way to retrieve the identity value from an identity column before saving a new register.
When I run this query:
Code:
"SELECT IDENT_CURRENT ('alpa_Animais') AS AnimalID"
directly, using the SQL Server Management Studio I get this value.
Does anyone know if there is a way to get this from a method inside a web app using Linq?
Thank you
Josi
Reply With Quote
  #2 (permalink)  
Old August 4th, 2010, 12:24 PM
Registered User
 
Join Date: Jul 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

//db is context name..select table name and enter field names in the braces
var Test_Details = from p in db.Test_Details select new { p.Column_names };
Reply With Quote
  #3 (permalink)  
Old August 4th, 2010, 12:59 PM
Imar's Avatar
Wrox Author
Points: 66,800, Level: 100
Points: 66,800, Level: 100 Points: 66,800, Level: 100 Points: 66,800, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,156
Thanks: 65
Thanked 1,393 Times in 1,373 Posts
Default

And how would select an ID for a new entity? All it does is select a specific column for all entities.....

AFAIK, it can't be done. I usually work around it using a GUID as an identity which I can assign when I create a new instance.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Row Insert using Linq arivarasuk ASP.NET 3.5 Professionals 1 January 9th, 2009 10:21 AM
Inserting & Retrieving Images on Sql Server adamusufi SQL Server 2000 6 June 26th, 2005 03:32 PM
Inserting Images and retrieving from SQL SERVER adamusufi VB.NET 2002/2003 Basics 0 June 24th, 2005 04:13 AM
Inserting a Value into an SQL Identity Field in VB vbmazza VB Databases Basics 1 April 27th, 2005 02:45 PM
Simple Question - SQL for retrieving different row wanda46 Access 5 June 9th, 2004 01:17 PM



All times are GMT -4. The time now is 12:20 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.