none
LINQ to SQL - Get operation with DBML going infinite loop. RRS feed

  • Question

  • Hi all ,

    I have created a simple db with following tables.

    Customer

    1) Customer id - PK

    2) First name

    3) Last name

    Order

    1) Orderid - PK

    2) Customer ID - FK

    3) Order date

    4) Comments

    Order details

    1) OrderDetailId - PK

    2) Orderid - FK

    3) Product id - FK

    Product

    1) Product Id -PK

    2) Product name

    After this , I have added a LINQ to SQL dbml files and dropped these 4 tables. I am fetching customer list from datacontext object as  var custList = from c in dbContext.customers select c.

    Problem -

    This operation works fine when there is no data in order and order detail table. But once I save data in order and order detail table for a particular customer , it goes in infinite loop and operation never completes. It is bit strange..

    Can someone please help me out with this?

    Siddhesh

    Thursday, February 9, 2012 9:56 AM

Answers

  • Hi Alan Chen ,

    We  have decided to use LINQ to entity ( Entity framework) instead of LINQ to SQL. Application works fine with Linq to Entitities framework.

    Thanks all involved in this chain for your valuable inputs.

    Siddhesh


    Siddhesh Sawant

    Friday, March 9, 2012 7:24 AM

All replies

  • Hi Siddhesh;

    Can you post the code you use to update Customer, Order, and Order Detail tables. Also show the code that causes the query to go into an infinite loop.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Thursday, February 9, 2012 4:46 PM
  • Hi fernando ,

    Customer is a master table . No DML operations on customer .

    To insert data in order and order detail I am using a SP which  takes parameters as

    @Comment

    @OrderDate

    @CustomerId

    @Total

    @ShipMethod

    @ProductId

    Where @product ID is comma seperated string of products.  SP does simple insertion in Order table first . Then it takes OrderId as Identity and use this to do insertion in order detail table for each product Id.

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------

    I am using this SP with DBML and WCF service just calls this SP as

    {

    int insertStatus = dataContext.InsertOrder(order.Comment, DateTime.Now, order.CustomerId, order.Total, order.ShipMethod, productIds);return insertStatus;

    }

    ---------------------------------------------------------------------------------------------------------Also following is WCF function which gets customer list and goes in infinite loop when I enter some data in Order and Order detail. It works fine when both tables are empty.

    public List<Customer> GetCustomers()AdventureWorksDataContext dataContext = new AdventureWorksDataContext();

    {

    var custList = from c in dataContext.Customers

    select c;

    return custList.ToList();

    }


    • Edited by Siddhesh S Friday, February 10, 2012 6:21 AM
    Friday, February 10, 2012 6:20 AM
  • Hi Siddhesh,

    Welcome to MSDN Forum.

    I have created the database as you posted and tested the code, everything works well. Because I don't know how you write the 'InsertOrder' Stored Procedure, so I insert the records mannually. If possible, please upload the demo to SkyDrive and post the link here, I will help you to solve the issue.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, February 13, 2012 5:17 AM
    Moderator
  • Hi Allen ,

    Thanks for reply .

    I have uploaded insert script at following location on skydrive

    https://skydrive.live.com/#cid=C8AE172EF094E6E5&id=C8AE172EF094E6E5%21107

    I have also uploaded WCF service class (SVC ) and DBML designer class at following location.

    https://skydrive.live.com/#cid=C8AE172EF094E6E5&id=C8AE172EF094E6E5%21109

    Please let me know if you can access it.

    Thanks

    Siddhesh


    Siddhesh Sawant

    Tuesday, February 14, 2012 9:43 AM
  • Hi Siddhesh;

    I tried downloading the files on your skydrive, either the files have been deleted or have not been marked for public viewing.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Tuesday, February 14, 2012 2:15 PM
  • Hi Siddhesh S,

    As @Fernando said, the files have already deleted, so we can't download them.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, February 15, 2012 5:29 AM
    Moderator
  • Hi Allen / fernando

    I have uploaded WCF function , insert procedure and DBML class at following public folder.

    https://skydrive.live.com/#cid=C8AE172EF094E6E5&id=C8AE172EF094E6E5%21105

    Please let me know if you can access the files.

    Thanks again for your help.

    Siddhesh


    Siddhesh Sawant

    Wednesday, February 15, 2012 9:53 AM
  • Hi Siddhesh S;

    From the code you posted I can see no reason for the problem you are having. Maybe Allen will spot something I was not able to.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, February 15, 2012 6:34 PM
  • Hi Siddhesh,

    I didn't find anything wrong with the code, I will do more research about it.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, February 16, 2012 8:21 AM
    Moderator
  • Hi Siddhesh,

    Could you please upload the complete project to skydrive and post the link here? I want to test the project and try to find the reason, just from the code, I didn't find anything wrong.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Friday, February 17, 2012 7:20 AM
    Moderator
  • Hi Allen,

    I have uploaded WCF service at following location

    https://skydrive.live.com/#cid=C8AE172EF094E6E5&id=C8AE172EF094E6E5%21123

    I have hosted this service on IIS 7 and consumed from silverlight client.

    Please let me know if more details are required.

    PS - strange thing is , I have tried out same with edmx (entity framework) and it works great. Not sure what is the issue with LINQ to SQL.

    Thanks

    Siddhesh


    Siddhesh Sawant

    Monday, February 20, 2012 6:09 AM
  • Hi Siddhesh S,

    I have involved my workmates to research the issue, it may need sometime, I will come back as soon as possible.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, February 22, 2012 8:44 AM
    Moderator
  • Hi Siddhesh,

    I downloaded your project, the only problem I can see is: you should Set Serialization Mode to "Unidirectional" in AdventureWorksDataContext property(Right click designer--->properties).

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 23, 2012 7:04 AM
    Moderator
  • Thanks Alan chen , 

    i will try it and let you know. 

    Siddhesh


    Siddhesh Sawant

    Thursday, February 23, 2012 7:27 AM
  • Hi Siddhesh,

    Any updates for your question now, thanks!

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 9, 2012 7:16 AM
    Moderator
  • Hi Alan Chen ,

    We  have decided to use LINQ to entity ( Entity framework) instead of LINQ to SQL. Application works fine with Linq to Entitities framework.

    Thanks all involved in this chain for your valuable inputs.

    Siddhesh


    Siddhesh Sawant

    Friday, March 9, 2012 7:24 AM