2
\$\begingroup\$

I am building a MySQL to Realmdb converter app.

I use Entity Framework to deal with MySQL, so below is the code of one of my model classes. I don't want to have multiple classes representing the same object, so instead of creating separate models for EF and Realm, I am using same model for both ORM's.

The question is, is there any way to improve it, make cleaner and neat, because I don't like putting [Key] for EF and then [PrimaryKey] for Realm and the same with [Index] and [Indexed]. Also does it affect the performance of reading/writing (having support for both ORM's in one model)

using Google.Protobuf.WellKnownTypes;
using MySql.Data.EntityFrameworkCore.DataAnnotations;
using Realms;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Text;

namespace Shared.Models
{
    [Table("phrase")]
    public class Phrase : RealmObject
    {
        [Key]
        [PrimaryKey]
        [Column("phrase_id")]
        public int Id { get; set; }

        [Column("entry_id")]
        public int EntryId { get; set; }

        [Index]
        [Indexed]
        [Column("content")]
        public string Content { get; set; }

        [Index]
        [Indexed]
        [Column("notes")]
        public string Notes { get; set; }

        [Column("created_at")]
        public string CreatedAt { get; set; }

        [Column("updated_at")]
        public string UpdatedAt { get; set; }
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.