PDA

View Full Version : سوال: 2 ارتباط یک به چند در code first



r4hgozar
چهارشنبه 04 شهریور 1394, 10:44 صبح
سلام.
من می خوام در code first 2 ارتباط یک به چند بدم. بصورت زیر

public string Url { get; set; }

public virtual ICollection<Gallery> Galleries { get; set; }
public virtual ICollection<GCategory> GCategories { get; set; }



این هم relation در database



//realtion
public Guid GCategoryId { get; set; }
public virtual GCategory GCategory { get; set; }
//relation
public Guid UploadId { get; set; }
public virtual Upload Upload { get; set; }



و قتی 2 تا ارتباط یک به چند دادم این ارور رو میده

Introducing FOREIGN KEY constraint 'FK_dbo.GCategories_dbo.Uploads_UploadId' on table 'GCategories' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint or index. See previous errors.

r4hgozar
پنج شنبه 05 شهریور 1394, 09:10 صبح
سلام.
دوستان اگه مشکل من رو داشتن لینک زیر می تونه کمکشون کنه. باید از fluent api استفاده کنید.
http://stackoverflow.com/questions/5559043/entity-framework-code-first-two-foreign-keys-from-same-table