locked
Ef Scheme for multi language translations. RRS feed

  • Question

  • User2131089582 posted

    I'm building simple web application where article can have multi language translation below is my database scheme in entity framework 

        public class Book
        {
            [Key]
            public int Id { get; set; }
            public int Number { get; set; }
            public string Content { get; set; }
            public virtual ICollection<Translation> Translations { get; set; }
        }
        public class Translation
        {
            [Key]
            public int Id { get; set; }
            public string Content { get; set; }
            public int LanguageId { get; set; }
            [ForeignKey("LanguageId")]
            public Language Language { get; set; }
            public int BookId { get; set; }
            [ForeignKey("BookId")]
            public Book Kitab { get; set; }
        }
        public class Language
        {
            [Key]
            public int Id { get; set; }
            public string Name { get; set; }
            public string KeyCode { get; set; }
        }

    I'm not sure if this is the right database scheme model, I'm plan to add search (in this case dropdown list) that has feature to choose language, for example if i choose english language it will show translation in english language.

    Tuesday, January 29, 2019 9:08 AM

All replies

  • User1120430333 posted

    IMO, where you should have started is at the database using MS SQL Server Management Stuido, created some tables, put some required data in them and started querying  using T-SQL

    The EF Model classes can wait. If you can't do it using SSMS and running some T-SQL, then you're not going to be successful  using EF.

    Tuesday, January 29, 2019 11:09 AM
  • User2131089582 posted

    it seems you don't read my explanation well, I have made the app using that scheme, but i want to make droprdownlist search so in will query based on the languange,

    Tuesday, January 29, 2019 12:39 PM
  • User1120430333 posted

    it seems you don't read my explanation well, I have made the app using that scheme, but i want to make droprdownlist search so in will query based on the languange,

    You don't understand what is being said to you. So you made some classes and made a database schema, but in the mean time,  you don't know how to query the database tables  that you should have done with T-SQL first using SSMS. What do you think EF is doing but making T-SQL to query the database tables that is derived from Linq to generate the T-SQL? This comes back to not knowing DBA 101 and using the ORM as a database admin tool. If you know how to use T-SQL and query the database tables, then it should be no problem figuring it out how to do the query using EF and Linq.

    Tuesday, January 29, 2019 11:13 PM
  • User1724605321 posted

    Hi hocamahdi99,

    I assume you have one dropdownlist where user could use which language the current book should be translated . So you will get book id and language id in server side after user select one language , then the query would be below based on your model :

    var result=db.Translations.FirstOrDefault(s => s.BookId == bookid && s.LanguageId == languageid);
    

    Best Regards,

    Nan Yu

    Wednesday, January 30, 2019 5:37 AM