when i am executing linq query i getting duplicate data

Posted by Ajaykumar.Pusarla under LINQ on 1/24/2014 | Points: 10 | Views : 817 | Status : [Member] | Replies : 3
var lst_test = from t in db.Tbl_Revenue where CIN == t.CIN && id == t.Financial_Year select t;

I getting the data by executing above linq query

TAG Element_Lable Element_Name Current_Year Previous_Year
TAG2274 Disclosure of revenue explanatory [Text Block] DisclosureOfRevenueExplanatoryTextBlock .
TAG2274 Disclosure of revenue explanatory [Text Block] DisclosureOfRevenueExplanatoryTextBlock .
TAG2274 Disclosure of revenue explanatory [Text Block] DisclosureOfRevenueExplanatoryTextBlock .

Actual Data is this one
TAG Element_Lable Element_Name Current_Year Previous_Year
TAG2274 Disclosure of revenue explanatory [Text Block] DisclosureOfRevenueExplanatoryTextBlock .
TAG2275 Share revenue from operations joint ventures ShareRevenueFromOperationsJointVentures .
TAG2276 Description of accounting policy for recognition of revenue DescriptionOfAccountingPolicyForRecognitionOfRevenue .





Responses

Posted by: kgovindarao523-21772 on: 1/24/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
Try like this,

var lst_test = (from t in db.Tbl_Revenue 
where CIN == t.CIN && id == t.Financial_Year
select t).Distinct().ToList();


Thank you,
Govind

Ajaykumar.Pusarla, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajaykumar.Pusarla on: 1/24/2014 [Member] Starter | Points: 25

Up
0
Down
 List<Tbl_Revenue> lst = new List<Tbl_Revenue>();
var lst_test = db.Tbl_Revenue.Where(t => id.Contains(t.Financial_Year) && CIN.Contains(t.CIN)).ToList<Tbl_Revenue>();

In Tbl_Revenue table 4 different rows are there but when i am executing above statements getting first row 4 times remaining rows are not coming
"db" is the dbcontext object

Ajaykumar.Pusarla, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Learningtorise on: 1/24/2014 [Member] Starter | Points: 25

Up
0
Down
Execute Relevant Query in SQL and figure out what's wrong by looking at ResultSet.
Using your LinQ Query i have deducted Query for SQL Server as Follows:

SELECT * FROM db.Tbl_Revenue
WHERE CIN = 'YourCIN' AND Financial_Year = 'YourID'

P.S: I may be wrong about my view!


http://hashtagakash.wordpress.com/

Ajaykumar.Pusarla, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response