1 Şubat 2020 Cumartesi

The INSERT statement conflicted with the FOREIGN KEY constraint hatası

İlişkili veritabanlarına veri eklemeye çalıştığımızda karşımıza çıkan bir hatadır. Bu hatanın 2 farklı kaynağı vardır. İlki, İlişki kurulmuş bir tabloda olmayan bir verinin, ilişki kurulan diğer tabloya eklenmeye çalışılması sırasında The INSERT statement conflicted with the FOREIGN KEY constraint hatası fırlatılır.

Bu hatanın fırlatılmasının diğer nedeni veri girilmesi zorunlu olan tabloya hiç veri girilmemesidir.
Örneğin;
aşağıdaki gibi iki POCO sınıfımız olsun.

    public class Topic : Entity
    {
        public const int MaxTitleLength = 90;
        [Required]
        [StringLength(MaxTitleLength)]
        public string Title { get; set; }
        public virtual ICollection Pegis { get; set; }
 
        public int CategoryId {get;set;}
        public virtual Category Category {get;set;}
    }
    public class Pegi : Entity
    {
        public long TopicId { get; set; }
        public string Title { get; set; }
        public virtual Topic Topic { get; set; }
    }
public class Category : Entity
{
    public string Title {get;set;}
    public virtual ICollection Topics {get;set;}
}

Burada Pegi varlığına bir TopicId belirtilmeden veri girilmeye çalışılırsa The INSERT statement conflicted with the FOREIGN KEY constraint hatası fırlatılır.

Benzer şekilde bir CaetgoryId belirtilmeden Topic girdisi yapılmaya çalışılırsa aynı hata fırlatılacaktır.

Bu durumdan kaçınmak için ya zorunlu olan varlık ile bir ilişkilendirme yapılmalı ya da TopicId ya da CategoryId nulleable olmalıdır

        public long? TopicId { get; set; }
        public int? CategoryId {get;set;}

13 Şubat 2018 Salı

Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on.

Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on.

When you are trying to modify UI (which is belong to main thread) via another thread. That's causes the problem.

You need to Make Thread-Safe Calls to Windows Forms Controls

8 Haziran 2016 Çarşamba

How To: Asp.NET Mvc Seo Frienly Urls

I saw a lot of questions about generating Asp.Net Mvc Seo Friendly Urls on internet. In this post im going to show you how to create your very own seo friendly urls like below.

17 Eylül 2015 Perşembe

No connection string named 'DefaultConnection' could be found in the application config file.

You added Connectionstring configuration to web.config file. Tried to migration, but you get error,
No connection string named 'DefaultConnection' could be found in the application config file.
And you dont know why this happening.

Its easy. You have to "Set as Start Up Project" the project containing connectionstring configuration.
And make sure that the execution of a command from Nuget console you choose the right project

12 Temmuz 2015 Pazar

Multi-platform programming of desktop Windows & Linux & Mac


However, the multi-platform programming Mobile , a new era will start in the coming days, the program is desktop.

JavaScript programming language of the future

The purpose of publishing this article in Javascript as the scripting language is to learn and develop the business.

Better PHP or ASP.NET

The two technologies ASP.NET and PHP web programming is usually used. For developers, there is the question of which technology is better?