Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > LINQ
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
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 };
 
Old August 4th, 2010, 12:59 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Row Insert using Linq arivarasuk ASP.NET 3.5 Professionals 1 January 9th, 2009 11: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.