How I solved Circular reference issue.
Since we do not want the collections that are added as a navigation
properties, the simplest thing to do was to copy the data into array.
Simply create a collection of the data you want.
public List<Order> GetOrders()
{
List<Order> orderList = new List<Order>();
var OrderQuery = from o in this.Context.Orders
select o;
foreach (var order in OrderQuery)
{
Order newOrder = new Order();
newOrder.OrderId = order.OrderId;
newOrder.Value = order.Value;
orderList.Add(newOrder);
}
return orderList;
}
On Jun 7, 12:29 pm, Nate <
southpointt...@gmail.com> wrote:
> I wanted to check with everyone here and see how they dealt with thecircularreferenceerror generated when using Linq to SQL or Entity
> framework. I followed the solution at this link and it seems to work
> so far but I wanted to make sure there wasn't a better solution to
> this problem.
>
> Solution I Used:
http://www.west-wind.com/weblog/posts/2007/Sep/02/LINQ-to-SQL-and-Ser...
>
> Thanks
>
> ERROR MESSAGE: Acircularreferencewas detected while serializing an
> object of type