Entity Framework - stworzenie prostej bazy danych

0

Witam,
Wchodzę w Entity Framework.

Stworzyłem sobie encję do tworzenia autorów. Generalnie ID, imię, nazwisko. Jeden autor mógł napisać wiele książek, a jedna książka mogła być stworzona przez wielu autorów. Jak najprościej za modelować to?

Próbowałem tak:

using System; using System.Collections.Generic; using System.Linq; using System.Web;

namespace Firmowa.Models
{
public class Author
{
public int AuthorId { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public virtual List<Book> Books { get; set; }
}
}


<code class="c#">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Firmowa.Models
{
    public class Book
    {
        public int BookID { get; set; }
        public string Title { get; set; }
        public string ISBN { get; set; }
        public virtual List<Author> Authors { get; set; }
        public uint year { get; set; }
        public string Publisher { get; set; }
    }
}
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; using System.Data.Entity.ModelConfiguration.Conventions; using Firmowa.Models; using Firmowa.Models.DAL;

namespace Firmowa.Models
{
public class BookContext : DbContext
{
public DbSet<Author> Authors { get; set; }
public DbSet<Book> Books { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    }
}

}


Niestety, nie uzyskuje pożądanego efektu.
0

Jak zdefiniujesz relacje wiele-do-wielu na poziome bazy danych (czyli tabela systemowa "books_autors (ref Autor_Id,ref Book_Id)", to odpowiedni model sam ci sie wygeneruje

0

Bardziej mi chodziło o coś takiego:
http://mikeyhogarth.wordpress.com/2011/02/05/implementing-many-to-many-relationships-in-mvc3/

Ale dzięki.

1 użytkowników online, w tym zalogowanych: 0, gości: 1