Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
I know the PHP code :

select id from customer where customer.name="salma"

how can I convert this code in MVC.

that means I want to get id for specific name by searching in MVC.

I need your help. please be ahead to help.
Posted
Comments
jo.him1988 8-Jul-14 2:56am    
don't know what are u saying, php n mvc both are different, if you want to run database query in mvc, create dataset or entity and write logic in controller's action and called it
rayhan12345 8-Jul-14 3:23am    
I want to get ID searching by name in MVC. I understand PHP that's why I said about PHP. But My problem in MVC.
Vi(ky 8-Jul-14 2:58am    
You can use same query or If You are using Entity Framework then use LINQ query Like

var result = (from c in DbContext.customer
where c.name == "salma"
select c).FirstOrDefault();
rayhan12345 8-Jul-14 3:20am    
but what will store in result? may i get full row of "salma" or only "id" for salma?
Vi(ky 8-Jul-14 5:02am    
Yes full row values. It will hold the object of Class customer with property values and you can access value like result.Id, result.Name etc.

1 solution

You can use same query or If You are using Entity Framework then use LINQ query Like

C#
var result = (from c in DbContext.customer
             where c.name == "salma"
             select c).FirstOrDefault();
 
Share this answer
 

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