473,410 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Circular Reference. I really need help ... thanks.

Hello,

On an ASP.NET MVC project I am getting a list of Tags which names
start with a string contained on the variable "q".

Everything works fine if no Post is related to Tags.
When there is relation I start to get a Circular Reference error.

I have been trying to solve this problem for days!
I can't find the reason for this, either in my SQL or C# code.

I am posting both codes ... just in case:

C# LINQ code:

public JsonResult Filter(string q, int limit) {

var list = (from t in database.Tags
where t.Name.StartsWith(q)
orderby t.Name
select t);
List<Tagtags = (limit 0 ? list.Take(limit) : list).ToList();
return this.Json(tags);

}

SQL Tables:

Expand|Select|Wrap|Line Numbers
  1. -- Files
  2. create table dbo.Files
  3. (
  4. FileID uniqueidentifier not null
  5. constraint PK_File primary key clustered,
  6. CreatedAt datetime null,
  7. Description nvarchar(2000) null,
  8. IsPublished bit null,
  9. Path nvarchar(800) null,
  10. Title nvarchar(400) null,
  11. UpdatedAt datetime null
  12. )
  13.  
  14. -- Posts
  15. create table dbo.Posts
  16. (
  17. PostID uniqueidentifier not null
  18. constraint PK_Post primary key clustered,
  19. Body nvarchar(max) null,
  20. CreatedAt datetime null,
  21. IsPublished bit null,
  22. Title nvarchar(400) null,
  23. UpdatedAt datetime null
  24. )
  25.  
  26. -- Tags
  27. create table dbo.Tags
  28. (
  29. TagID uniqueidentifier not null
  30. constraint PK_Tag primary key clustered,
  31. [Name] nvarchar(100) null
  32. )
  33.  
  34. -- FilesTags
  35. create table dbo.FilesTags
  36. (
  37. FileID uniqueidentifier not null,
  38. TagID uniqueidentifier not null,
  39. constraint PK_FilesTags
  40. primary key clustered (FileID, TagID),
  41. constraint FK_FilesTags_Files
  42. foreign key(FileID)
  43. references dbo.Files(FileID)
  44. on delete cascade,
  45. constraint FK_FilesTags_Tags
  46. foreign key(TagID)
  47. references dbo.Tags(TagID)
  48. on delete cascade
  49. )
  50.  
  51. -- PostsTags
  52. create table dbo.PostsTags
  53. (
  54. PostID uniqueidentifier not null,
  55. TagID uniqueidentifier not null,
  56. constraint PK_PostsTags
  57. primary key clustered (PostID, TagID),
  58. constraint FK_PostsTags_Posts
  59. foreign key(PostID)
  60. references dbo.Posts(PostID)
  61. on delete cascade,
  62. constraint FK_PostsTags_Tags
  63. foreign key(TagID)
  64. references dbo.Tags(TagID)
  65. on delete cascade
  66. )
  67.  
  68.  
DATA in Tables (All other tables are empty):

Posts

PostID: 78ef0b05-ca4c-4df8-88c9-2858d24fa4e3
Body: <p>Test</p>
CreateAt: 03-09-2008 22:35:25
IsPublished: True
Title: This is the title
UpdatedDate: 03-09-2008 22:35:25

Tags

TagID: e2ec18a7-d668-477b-977b-183989df2a65
Name: Net

TagID: dbf4465a-d0f6-4145-831d-b1ce1363dd16
Name: New York

TagID: 0ea15666-155b-4237-a871-d905a2685f45
Name: Australia

PostsTags

TagID: e2ec18a7-d668-477b-977b-183989df2a65
PostID: 78ef0b05-ca4c-4df8-88c9-2858d24fa4e3

TagID: dbf4465a-d0f6-4145-831d-b1ce1363dd16
PostID: 78ef0b05-ca4c-4df8-88c9-2858d24fa4e3

My Linq code is automaticly generated by LinqToSQL in VS2008.

I don't see any problem in my code or data but I get the error:

A circular reference was detected while serializing an object of type
'MyApp.Models.Post'

I detected the error in FireFox FireBug because the AutoComplete most
of the time does not work.

Does anyone sees anything wrong?!

Thanks,
Miguel
Sep 4 '08 #1
3 2930
"shapper" <md*****@gmail.comwrote in message
news:78**********************************@w24g2000 prd.googlegroups.com...
Everything works fine if no Post is related to Tags.
When there is relation I start to get a Circular Reference error.

I have been trying to solve this problem for days!
I can't find the reason for this, either in my SQL or C# code.

I am posting both codes ... just in case:

C# LINQ code:

public JsonResult Filter(string q, int limit) {

var list = (from t in database.Tags
where t.Name.StartsWith(q)
orderby t.Name
select t);
List<Tagtags = (limit 0 ? list.Take(limit) : list).ToList();
return this.Json(tags);

}
Without the definition for Json() method, this doesn't tell much.

Sep 4 '08 #2
On Sep 4, 3:14*pm, "Pavel Minaev" <int...@gmail.comwrote:
"shapper" <mdmo...@gmail.comwrote in message

news:78**********************************@w24g2000 prd.googlegroups.com...
Everything works fine if no Post is related to Tags.
When there is relation I start to get a Circular Reference error.
I have been trying to solve this problem for days!
I can't find the reason for this, either in my SQL or C# code.
I am posting both codes ... just in case:
C# LINQ code:
* *public JsonResult Filter(string q, int limit) {
* * *var list = (from t in database.Tags
* * * * * * * * *where t.Name.StartsWith(q)
* * * * * * * * *orderby t.Name
* * * * * * * * *select t);
* * *List<Tagtags = (limit 0 ? list.Take(limit) : list).ToList();
* * *return this.Json(tags);
* *}

Without the definition for Json() method, this doesn't tell much.
JSON is from ASP.NET MVC Preview 5...

I found the a explanation for this in: http://www.west-wind.com/Weblog/posts/147218.aspx

I was reading the article but its explanation implies changes to the
model which he also says that have a downside.

In this case I am serializing a list of Tags ... each Tag has 2
properties: TagID and Name ...

All I need is only the names of the selected Tags ... so couldn't I
just pick the Names of all Tags in the list create an object or a new
list and serialize it?

Maybe a list of String? An Array?

Maybe this would solve the problem without needing to change the
model ...

Any idea how to do this?

Thanks,

Miguel
Sep 4 '08 #3
On Sep 4, 4:54*pm, shapper <mdmo...@gmail.comwrote:
On Sep 4, 3:14*pm, "Pavel Minaev" <int...@gmail.comwrote:
"shapper" <mdmo...@gmail.comwrote in message
news:78**********************************@w24g2000 prd.googlegroups.com....
Everything works fine if no Post is related to Tags.
When there is relation I start to get a Circular Reference error.
I have been trying to solve this problem for days!
I can't find the reason for this, either in my SQL or C# code.
I am posting both codes ... just in case:
C# LINQ code:
* *public JsonResult Filter(string q, int limit) {
* * *var list = (from t in database.Tags
* * * * * * * * *where t.Name.StartsWith(q)
* * * * * * * * *orderby t.Name
* * * * * * * * *select t);
* * *List<Tagtags = (limit 0 ? list.Take(limit) : list).ToList();
* * *return this.Json(tags);
* *}
Without the definition for Json() method, this doesn't tell much.

JSON is from ASP.NET MVC Preview 5...

I found the a explanation for this in:http://www.west-wind.com/Weblog/posts/147218.aspx

I was reading the article but its explanation implies changes to the
model which he also says that have a downside.

In this case I am serializing a list of Tags ... each Tag has 2
properties: TagID and Name ...

All I need is only the names of the selected Tags ... so couldn't I
just pick the Names of all Tags in the list create an object or a new
list and serialize it?

Maybe a list of String? An Array?

Maybe this would solve the problem without needing to change the
model ...

Any idea how to do this?

Thanks,

Miguel
Just solved it:

// Define list
var list = (from t in database.Tags
where t.Name.StartsWith(q)
orderby t.Name
select t.Name);

// Define tags
string[] tags = (limit 0 ? list.Take(limit) : list).ToArray();

// Return tags
return this.Json(tags);

Thanks,
Miguel
Sep 4 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Leslie | last post by:
I have 2 dlls and they reference each other, thus causing the circular dependence error. I have read about other cases and people say use Interfaces to solve the problem with the shared methods. ...
11
by: Steve Jorgensen | last post by:
I just came up with a really tidy little solution to the VB/VBA circular reference issue. It only works with Access 2000 or newer, but that's about the only down-side. The issue... You need an...
4
by: Henke | last post by:
I have this scenario. public class A { public int numbers; public class A() { }
4
by: pnp | last post by:
I'm developing an app (in C #) that uses 2 usercontrols that must be in different dll's. The problem is that each one needs to use the other, so as a result I get a circular reference error when I...
16
by: PromisedOyster | last post by:
Hi I have a situation where I want to use circular referencing. I have cut down the example for demonstration purposes. Say we have one executable (main.exe) and two DLLS (A1.dll and A2.dll)....
6
by: Stephen Robertson | last post by:
We are currently in a dead end with a circular reference issue using vb.net, and are hoping someone might help us resolve it. Idea... We have frmmain calling frmperson (dim f as new frmperson)...
3
by: Solution Seeker | last post by:
Hi All, I am here with a Query and need a Solution for it. The Query is as Follows, We have 3 Projects in a Solution - Say UI, CMN and PRD First One Deals with UI Forms Second One Deals...
8
by: nyhetsgrupper | last post by:
I have written a windows service and want to expose a web based user interface for this service. I then wrote a class library containing a ..net remoting server. The class library have a method...
2
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I'm reying to get around the problem of cross page post back. I'm attempting to use an interface to cast the previous page. if (PreviousPage != null) { ICommonPostback frm = PreviousPage as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.