Click here to Skip to main content
15,886,795 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
hi sir,
I want to pick up ID from Given name in database Using Linq query.

DESCRIPTION:
Here i type Country ,State name in excel sheet.For bulk upload, i want to store ID in database and name shown in grid index. Here i want to using Linq query For this.And i'm using MVC 5 Repository pattern.
Kindly help me for this task.
Posted
Comments
Jameel VM 21-Sep-14 3:09am    
did you try anything?how can we help without any code sample? you will get so many hints by searching google about linq and Repository pattern.

1 solution

This solution is an anticipation from your question:-

C#
var id = Context."NAME".Where(x => x.Name == name).Select(x => x.ID);


Pass the name as parameter to the fuction. Hoping name is unique.
Thanks
:)
 
Share this answer
 
v2
Comments
JOTHI KUMAR Member 10918227 23-Sep-14 1:46am    
Where i put this function Kindly guide me sir bcz im new in mvc repository pattern
[no name] 23-Sep-14 2:47am    
this should be in your repository, or the context files. Where you are doing the Database operation.
JOTHI KUMAR Member 10918227 23-Sep-14 2:56am    
context
[no name] 23-Sep-14 2:58am    
yes context. You must be having db operations place right!! You would be having one place where all db operations are done!! Can you place atleast your code? We will get to know from that. As you have mentioned you have used repository pattern.
JOTHI KUMAR Member 10918227 23-Sep-14 2:59am    
hmm yeah i used repository also

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900