Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

EF code first and FK mention

$
0
0

just view this link http://www.learnentityframeworkcore.com/configuration/data-annotation-attributes/foreignkey-attribute

public class Book
{
    public int BookId { get; set; }
    public string Title { get; set; }
    public Author Author { get; set; }
    [ForeignKey("Author")]
    public int AuthorFK { get; set; }
}
public class Author
{
    public int AuthorId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    [ForeignKey("AuthorFK")]
    public ICollection<Book> Books { get; set; }
}

why do we need to mention FK columns in two model class ? is it necessary?

what the article try to explain?

if i mention FK in books class does it work or do i need to mention FK in book and author both class ?

please guide.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>