c# - Why does LINQ Query return more results/rows than the table I am querying? -


For reference, I am working on data conversion 1 time from Excel Sheets that I have imported into a database . The data is not normalized and I am trying to normalize it.

I have 3 tables in a SQL database. They are called Old Assets, Old Transaction and Old Greece.

The old Transaction is OldAssets OldUsers 7903 record 7437. 9764

I am using LINQ where these tables OldUsers of OT in OldTransactions u this code OldAssets < / p>

  to SQL to query using oa (Oa.Asset_Serial_Number == ot.Asset_Serial_Number and amp; ot.User_EID == u.User_EID & amp; ot.Asset_Tag == oa.Asset_Tag) select new transaction {DevCenter = ot.Transaction_Dev_Center, action = ot.Transaction_Action, status = ot.Transaction_Status, ModificationDate = ot.Modified, ModifiedBy = ot.ModifiedBy, CreatedBy = ot.CreatedBy, TransactionDate = (System .DateTime) ot.Transaction_Date, Transaction_Asset = (System.Int32) oa.ID, Transaction_User = (system .Int32) u.ID}   

I have been through all your OldTransactions and go to each OldTransaction, a new transaction Trying to make that Transaction_Asset and Transaction_User specifies the basis of the mapping of a property serial number and a user_EID.

My result is giving me more than 10,000 records of new transactions. I do not understand how I can have more records than earlier transactions.

What questions can I write that will return a new transaction for every old transaction, but with the added properties of Transaction_Asset and Transaction_User based on serial_number and mapping of User_EID?

From your question it seems that you want to copy all the transactions with additional data. I think something could work like this:

 New transaction selection in  OT in OldTransactions {DevCenter = ot.Transaction_Dev_Center, verb = ot.Transaction_Action, position = ot.Transaction_Status , ModificationDate = ot.Modified, ModifiedBy = ot.ModifiedBy, CreatedBy = ot.CreatedBy, TransactionDate = (System.DateTime) ot.Transaction_Date, Transaction_Asset = (System.Int32) (where oa.Asset_Serial_Number == ot the oa in OldAssets. Asset_Serial_Number & amp; & amp; OT. Asset_Tag select == oa.Asset_Tag oa.ID) .FirstOrDefault (), Transaction_User = (System.Int32) u.User_EID where ot.User_EID == in OldUsers the (u u. Select ID). FirstOrDefault ())}    

Comments