Advertisement
Guest User

Untitled

a guest
Jun 1st, 2015
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.73 KB | None | 0 0
  1. using System;
  2. using System.Data.Common;
  3. using System.Data.SqlClient;
  4. using System.Data.Entity;
  5. using System.Data.EntityClient;
  6. using System.Data.Entity.Design;
  7. using System.Data.Entity.Infrastructure;
  8.  
  9. namespace DynamicOrm1
  10. {
  11.     class Generators
  12.     {
  13.         internal EntityModelSchemaGenerator Models { get; set; }
  14.         internal EntityClassGenerator Classes { get; set; }
  15.         internal EntityCodeGenerator Code { get; set; }
  16.         internal EntityViewGenerator Views { get; set; }
  17.         internal EntityStoreSchemaGenerator Store { get; set; }
  18.  
  19.         const string connectionString = "Server = MSSQL2014; Database = test.shop; Trusted_Connection = True;";
  20.         const string providerInvariantName = "System.Data.SqlClient";
  21.  
  22.         public Generators()
  23.         {
  24.             InitializeSettings();
  25.         }
  26.  
  27.         private void InitializeSettings()
  28.         {
  29.             Classes = new EntityClassGenerator(LanguageOption.GenerateCSharpCode);
  30.             Code = new EntityCodeGenerator(LanguageOption.GenerateCSharpCode);
  31.             Views = new EntityViewGenerator(LanguageOption.GenerateCSharpCode);
  32.             Store = new EntityStoreSchemaGenerator(providerInvariantName, connectionString, "ShoppingModelStore");
  33.  
  34.             Store.GenerateForeignKeyProperties = true;
  35.         }
  36.  
  37.         internal void CreateSsdlFile(string filePath)
  38.         {
  39.             if (filePath == String.Empty)
  40.                 throw new Exception("Can't create the SSDL file, because the given file path is an empty string.");
  41.  
  42.             Store.GenerateStoreMetadata();
  43.             Store.WriteStoreSchema(filePath);
  44.         }
  45.  
  46.         internal void CreateCsdlAndMslFile(string csdlFilePath, string mslFilePath)
  47.         {
  48.             if (Store == null)
  49.                 throw new Exception("Can't create the CSDL and MSL files, because the `Store` object is null.");
  50.  
  51.             Models = new EntityModelSchemaGenerator(Store.StoreItemCollection, "ShoppingModelConceptual", "ShoppingModelConceptualContainer");
  52.             Models.GenerateMetadata();
  53.             Models.WriteModelSchema(csdlFilePath);
  54.             Models.WriteStorageMapping(mslFilePath);
  55.         }
  56.     }
  57.  
  58.     class Program
  59.     {
  60.         private static Generators EntityGenerators { get; set; }
  61.  
  62.         [STAThread]
  63.         static void Main()
  64.         {
  65.             try
  66.             {
  67.                 EntityGenerators = new Generators();
  68.                 EntityGenerators.CreateSsdlFile(@"\shopping.ssdl.xml");
  69.                 EntityGenerators.CreateCsdlAndMslFile(@"\shopping.csdl.xml", @"\shopping.msl.xml");
  70.             }
  71.             catch (Exception exception)
  72.             {
  73.                 Console.WriteLine(exception.Message);
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement