protected override void OnModelCreating(IModelAccessor modelAccessor) { modelAccessor.ConnectionString = "Data Source=localhost;Initial Catalog=Test;Integrated Security=True;"; modelAccessor.UseEntityFramework(modelBuilder => { modelBuilder.Entity <ModuleConfig>().HasKey(x => new { x.IdModule }); }); }
/// <summary> /// Предоставляет доступ к процессу создания модели в EntityFramework через делегат <paramref name="modelBuilderDelegate"/>. /// </summary> public static void UseEntityFramework(this IModelAccessor modelAccessor, Action <DbModelBuilder> modelBuilderDelegate) { if (modelAccessor is Internal.ModelAccessorInternal modelAccessorInternal) { modelAccessorInternal.ModelBuilderDelegate = modelBuilderDelegate; } else { throw new InvalidOperationException("This can be used only for EF context."); } }
/// <summary> Implements <see cref="IModelDefinitionManager.GetAccessors"/> </summary> public IModelAccessor GetAccessor(string Ident) { lock (syncObj) { IModelAccessor ret = null; if (ModelAccessorByIdent != null) { ModelAccessorByIdent.TryGetValue(Ident, out ret); } return(ret); } }
public static IModelAccessorGroup CreateInstance(ModelDefinitionManager parent, XmlModelAccessorGroup definition) { if (definition == null) { return(null); } ModelAccessorGroup group = new ModelAccessorGroup(); try { if (string.IsNullOrEmpty(definition.Name)) { throw new EtkException("'Name' is mandatory"); } group.Parent = parent; group.Name = definition.Name.EmptyIfNull().Trim(); group.Description = definition.Description.EmptyIfNull().Trim(); if (definition.Accessors != null) { foreach (XmlModelAccessor xmlAccessor in definition.Accessors) { //IModelAccessor accessor = CreateModelAccessors(modelAccessorDefinition); IModelAccessor accessor = ModelAccessor.CreateInstance(group, xmlAccessor); if (accessor != null) { group.accessors.Add(accessor); if (parent.ModelAccessorByIdent.ContainsKey(accessor.Ident)) { Logger.Instance.LogFormat(LogType.Warn, "The model accessor '{0}' is declared more than once.", accessor.Ident); } parent.ModelAccessorByIdent[accessor.Ident] = accessor; } } } } catch (Exception ex) { throw new EtkException($"Cannot create 'Model Accessor Group' '{definition.Name.EmptyIfNull()}': {ex.Message}"); } return(group); }
public ModelLinkProperty(ModelType parent, XmlModelLinkProperty xmlLinkProperty) { try { Parent = parent; Name = xmlLinkProperty.Name.EmptyIfNull().Trim(); Description = xmlLinkProperty.Description.EmptyIfNull().Trim(); string accessorName = xmlLinkProperty.Accessor.EmptyIfNull().Trim(); if (parent == null) { throw new EtkException("'Parent Type' is not defined"); } if (string.IsNullOrEmpty(Name)) { throw new EtkException("'Name' cannot be null or empty"); } if (string.IsNullOrEmpty(accessorName)) { throw new EtkException("'Accessor' cannot be null or empty"); } IModelAccessor accessor = Parent.Parent.GetAccessor(accessorName); if (accessor == null) { throw new EtkException($"Cannot find the 'Accessor' '{accessorName}'"); } LinkedModelAccessor = accessor; IsACollection = LinkedModelAccessor.ReturnTypeIsACollection; IEnumerable <string> keys = null; if (!string.IsNullOrEmpty(xmlLinkProperty.Keys)) { keys = xmlLinkProperty.Keys.Split(',').Select(k => k.Trim()).Where(k => string.IsNullOrEmpty(k)); } } catch (Exception ex) { throw new EtkException($"Linked Property '{Name.EmptyIfNull()}' creation failed: {ex.Message}"); } }
/// <summary> /// —м. <see cref="UnitOfWorkBase.OnModelCreating(IModelAccessor)"/>. /// </summary> protected virtual void OnModelCreatingCustom(IModelAccessor modelAccessor) { }
/// <summary> /// </summary> protected sealed override void OnModelCreating(IModelAccessor modelAccessor) { modelAccessor.ConnectionString = ConnectionString; OnModelCreatingCustom(modelAccessor); modelAccessor.ConnectionString = ConnectionString; }
/// <summary> /// Initializes a new instance of the <see cref="CommandLineServiceProvider" /> class. /// </summary> /// <param name="modelAccessor">The model accessor.</param> public CommandLineServiceProvider(IModelAccessor modelAccessor) => _modelAccessor = modelAccessor;