在linq中加入查询错误 [英] join query error in linq

查看:84
本文介绍了在linq中加入查询错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 st obj.Wishlist_tables
join X obj.movi​​e_details on st.movi​​e_id等于X.Id
其中 st.username == Session [ user]。ToString()
选择 new {st,X};
dl1.DataBind();



此查询未从两个表中获取结果。任何能够正确执行此操作的人?

解决方案

 来自 st  obj.Wishlist_tables中的class =code-keyword> 
join X in obj.movi​​e_details on st.movi​​e_id等于X.Id
其中 st.username ==会话[ user]。ToString()
选择 new {X.Image_path,X.label,X.Movie_Name,X.price,st.movi​​e_id,st.movi​​e_name,st.username};


首先在本机SQL中尝试相同的查询,看看它是否返回任何结果。可能是Db中没有匹配的记录,或者用户不匹配。确保在sql中使用equi-join。

如果有特定错误,则发布相同的详细信息,显示包含数据的表格结构的片段。



除了你的查询的纯语法术语没有错误


 来自 st   obj.Wishlist_tables 
join X in obj.movi​​e_details on st.movi​​e_id等于X.Id
其中 st.username == Session [ user]。ToString()
选择 new {X.Image_path,X.label,X.Movie_Name,X.price,st.movi​​e_id,st.movi​​e_name,st.username};


dl1.DataSource = from st in obj.Wishlist_tables
                 join X in obj.movie_details on st.movie_id equals X.Id
                 where st.username == Session["user"].ToString()
                 select new {st, X };
dl1.DataBind();


This query is not taking result from both tables. Anyone who can do this correctly?

解决方案

from st in obj.Wishlist_tables
                             join X in obj.movie_details on st.movie_id equals X.Id
                             where st.username == Session["user"].ToString()
                             select new { X.Image_path, X.label, X.Movie_Name, X.price, st.movie_id, st.movie_name, st.username };


First try the same query in native SQL and see if it returns any result. It can be that there are no matching records in Db or the user is not matching. Make sure you use equi-join in sql.
If there are specific errors then post details of the same, showing a snippet of table's structure with data.

Apart, there is nothing wrong in pure syntax terms with your query


from st in obj.Wishlist_tables
                             join X in obj.movie_details on st.movie_id equals X.Id
                             where st.username==Session["user"].ToString()
                             select new { X.Image_path,X.label,X.Movie_Name,X.price,st.movie_id,st.movie_name,st.username};


这篇关于在linq中加入查询错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆