We want to display user details by using user id . Based on this id we want to display username and password into console application . copy and paste following code into console application.
private static void SingleRecord()
{
Console.WriteLine("\nEnter your Account ID--------:");
int id= int.Parse(Console.ReadLine());
User user = new User();
user.Id = id;
List<User> us = GetAccountRecord(id);
Console.WriteLine("\nYour Account Record..................");
foreach (var cont in us)
{
Console.WriteLine("Your Account Id is :" + cont.Id);
Console.WriteLine("Your Account Username is :" + cont.username);
Console.WriteLine("Your Account Password is :" + cont.password);
}
/* Console.WriteLine( "Your Account Id is :"+id);
Console.WriteLine("Your Account Username is :" + user.username);
Console.WriteLine("Your Account Password is :" + user.password);*/
Console.ReadLine();
}
public static List<User> GetAccountRecord(int User_Id)
{
using (ModelContainer ctx = new ModelContainer())
{
var query = (from a in ctx.Users
where a.Id == User_Id
select a).Distinct();
List<User> userList = new List<User>();
query.ToList().ForEach(rec =>
{
userList.Add(new User
{
Id = rec.Id,
username = rec.username,
password = rec.password
});
});
return userList;
}
}
Here is the result when you run the application .
No comments:
Post a Comment