public void CreateModel_GetTables_Has_No_Duplicates()
 {
     var model = new AttributeMappingSource().GetModel(typeof(MyDataContext2));
     var tables = model.GetTables().ToList();
     Assert.AreEqual(1, tables.Count);
     Assert.AreEqual("dbo...FooTable", tables[0].TableName);
 }
Example #2
0
 public MessageRepository(IMapper<Message, MessageDocument> messageDocumentMapper)
 {
     this.messageDocumentMapper = messageDocumentMapper;
     mappingSource = new AttributeMappingSource();
     connectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
     context = new AppContext(connectionString);
 }
Example #3
0
 static void CreateOrUpdateDatabase(Type type, string cs, string scriptFile)
 {
     MetaModel model = null;
     if (type != null)
     {
         var ms = new AttributeMappingSource();
         model = ms.GetModel(type);
     }
     if (cs.IsNullOrEmpty())
     {
         try
         {
             var x = (DataContext)Activator.CreateInstance(type, true);
             cs = x.Connection.ConnectionString;
         }
         catch (Exception e)
         {
             throw new Exception("Cannot obtain connection string from DataContext " + type, e);
         }
     }
     if (cs.IsNullOrEmpty())
     {
         throw new Exception("ConnectionString not provided for DataContext: " + type);
     }
     Log.Inform("Updating database from type {0}, {1}", type, cs);
     Log.Inform(cs);
     Log.Inform("{0}", type);
     //dc.Log = Console.Out;
     var ms2 = new MetaSynchronizer(model, cs);
     ms2.ScriptFile = scriptFile;
     ms2.Log = Log;
     ms2.WindowsUsername = Program.Options.WindowsUsername;
     ms2.CreateOrUpdateDatabase(Options.AutoCreate.GetValueOrDefault(), Options.AutoUpdate.GetValueOrDefault());
 }
Example #4
0
        public void CreateModel_GetTables_Has_No_Duplicates()
        {
            var model  = new AttributeMappingSource().GetModel(typeof(MyDataContext2));
            var tables = model.GetTables().ToList();

            Assert.AreEqual(1, tables.Count);
            Assert.AreEqual("dbo...FooTable", tables[0].TableName);
        }
Example #5
0
        public static List <MetaDataMember> ReadProperties(this DataContext dc, Type type, ref WSStatus statusLines)
        {
            lock (ReadPropertiesLock)
            {
                try
                {
                    AttributeMappingSource ams = new System.Data.Linq.Mapping.AttributeMappingSource();
                    MetaModel model            = ams.GetModel(dc.GetType());
                    var       meta             = model.GetTable(type);

                    return(meta.RowType.DataMembers.Where(x => x.IsPersistent).ToList());//TODO@ANDVO : avoid using '.ToList()' to speed up execution
                }
                catch (Exception) { }
                return(null);
            }
        }
 public void Ctor_FileOrServerOrConnectionIsServer()
 {
     MappingSource mapping = new AttributeMappingSource();
     string fileOrServerOrConnection = "ThisIsAssumedToBeAServerName";
     new DataContext(fileOrServerOrConnection, mapping);
 }
 public void Ctor_FileOrServerOrConnectionIsFilename()
 {
     MappingSource mapping = new AttributeMappingSource();
     string fileOrServerOrConnection = typeof(DataContextTest).Assembly.Location;
     new DataContext(fileOrServerOrConnection, mapping);
 }
 public void Ctor_FileOrServerOrConnectionIsNull()
 {
     MappingSource mapping = new AttributeMappingSource();
     string fileOrServerOrConnection = null;
     new DataContext(fileOrServerOrConnection, mapping);
 }
 private bool IsPrimaryKey(MemberExpression m)
 {
     AttributeMappingSource mappingSource = new AttributeMappingSource();
     MetaModel mapping = mappingSource.GetModel(m.Member.DeclaringType);
     MetaTable table = mapping.GetTable(m.Member.DeclaringType);
     foreach (MetaDataMember dataMember in table.RowType.PersistentDataMembers) {
         if (dataMember.Name == m.Member.Name) {
             return dataMember.IsPrimaryKey;
         }
     }
     return false;
 }
 private string GetTableName(Type tableType)
 {
     AttributeMappingSource mappingSource = new AttributeMappingSource();
     MetaModel mapping = mappingSource.GetModel(tableType);
     MetaTable table = mapping.GetTable(tableType);
     return table.TableName;
 }
 private Type GetMemberType(MemberExpression m)
 {
     AttributeMappingSource mappingSource = new AttributeMappingSource();
     MetaModel mapping = mappingSource.GetModel(m.Member.DeclaringType);
     MetaTable table = mapping.GetTable(m.Member.DeclaringType);
     foreach (MetaDataMember dataMember in table.RowType.PersistentDataMembers) {
         if (dataMember.Name == m.Member.Name) {
             return dataMember.Type;
         }
     }
     return null;
 }