How can impliment the drop drop down list and Retrurn List using LINQ sqls from two table RRS feed

  • Question

  • User-1355965324 posted

    Hi Sorry for asking  the very basic question again and again because I am new in Entity frame work

    Currently I have implimented the drop downlist as the given below

    public DbSet<GoUserDepotLink> goUserDepotLink { get; set; }
    public DbSet<GoUserModel> goUser { get; set; }

    UserDepot Model UserID int Depotno int IsDefault boolean [Not Mapped] DepotName string Depot Model DepotNo int DepotName Currently I am doing the dropdown using the following EmployeeBLL.GetUserDepots stored Procedure Select DepotName,DepotNumber, IsDefault from UserDepot A, Depot B Inner join A.Depotno = b.DepotNo And A.userid = id; then after public static List<SelectListItem> GetUserDepots(int userId, IOptions<ConnectionSetting> connectionSettings) { List<SelectListItem> menu = new List<SelectListItem>(); DataTable dt = new DataTable(); dt = EmployeeBLL.GetUserDepots(userId, connectionSettings); if (dt.Rows.Count > 0) { menu = dt.AsEnumerable().Select(row => { var p = new SelectListItem { Value = row["DepotNo"].ToString(), Text = row["DepotName"].ToString(), Selected = Convert.ToBoolean(row["IsDefaultDepot"].ToString()) }; return p; }).ToList<SelectListItem>(); }

    Now how can I implement the same List result as return  using LINQ

    UserDepot Model.cs
    UserID int
    Depotno  int
    IsDefault boolean
    [Not Mapped]
    DepotName string 
    [Not Mapped]

    Depot Model.cs DepotNo int DepotName chane the way of calling in entity framework using LinQ statement from two table using two model private readonly GoContext ctx; public UserDepotRepository(GoContext db) { ctx = db; } public IEnumerable<UserDepot> GetUserDepots(int UserID) { var DepotUserList= Select DepotNo,Depotname, IsDefault from Where UserModel.userId= UserID and UserDepot.UerId= UserID /// Here I am looking how to impliment the Linq from UserDepot and User model
    to get all Depots for the given UserId linked into the UserDepots using Linq return DepotUserList; } public long Add(User User) { ctx.Usermodel.Add(User); long Userid= ctx.SaveChanges(); return UserID; }

    With Many Many thanks to all

    Tuesday, November 5, 2019 9:09 AM


All replies