I'm developing an application which uses some projects.
as you know MVC has built-in security authentication which can be used as code-first,so did I.
In my Main-project I have used IdentityModels.cs to create default tables such as aspnetusers and so on.
in aspnetUsers I want to add a few field such as FirstName,LastName and CityID which has a relationship to City model.
My City Model is in another project which named DomainClasses.
So far I have two projects ,first is Main-Project and the second one is domain classes.
I want to add cityId in my aspnetusers tables which has a relation to City table.
I have added DomainClass reference in Main-Project
these are my codes:
using DomainClasses;
public class ApplicationUser : IdentityUser
{
[MaxLength(25)]
public string FirstName { get; set; }
[MaxLength(50)]
public string LastName { get; set; }
public int PersonalCode { get; set; }
public int CityID { get; set; }
//
public City Cities { get; set; }
...
...
}
so in I must add applicationuser in my city class too.
public class City
{
public int CityID { get; set; }
[MaxLength(30)]
public string CityName { get; set; }
public int CityCode { get; set; }
//I get error in here
public ICollection<ApplicationUser> AppllicationUsers { get; set;}
}
when I want to add Mainproject reference I get circular reference issue.
Member
112 Points
398 Posts
Circular reference
Oct 01, 2018 01:00 PM|vahid.ch|LINK
Hello
I'm developing an application which uses some projects.
as you know MVC has built-in security authentication which can be used as code-first,so did I.
In my Main-project I have used IdentityModels.cs to create default tables such as aspnetusers and so on.
in aspnetUsers I want to add a few field such as FirstName,LastName and CityID which has a relationship to City model.
My City Model is in another project which named DomainClasses.
So far I have two projects ,first is Main-Project and the second one is domain classes.
I want to add cityId in my aspnetusers tables which has a relation to City table.
I have added DomainClass reference in Main-Project
these are my codes:
so in I must add applicationuser in my city class too.
when I want to add Mainproject reference I get circular reference issue.
how can I fix that?
thanks.
All-Star
58254 Points
15681 Posts
Re: Circular reference
Oct 01, 2018 02:44 PM|bruce (sqlwork.com)|LINK
unlike other runtimes, .net projects can not refer to each other. Move the Identity models to the other project.
All-Star
18815 Points
3831 Posts
Re: Circular reference
Oct 02, 2018 02:55 AM|Nan Yu|LINK
Hi vahid.ch ,
You can try :
1. Move your models into a third class assembly that is referenced by both of your projects.
2. Reduce complexity by keeping the Model, View, Controller classes in the same project.
Best Regards,
Nan Yu