Skip to content

Instantly share code, notes, and snippets.

@pil0t
Created May 30, 2014 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pil0t/b557864154dc4d52ad51 to your computer and use it in GitHub Desktop.
Save pil0t/b557864154dc4d52ad51 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
using Xtensive.Orm;
using Xtensive.Orm.Building.Definitions;
using Xtensive.Orm.Configuration;
using Module = Xtensive.Orm.Building.Module;
internal class Program
{
private static void Main(string[] args)
{
var domainConfiguration = new DomainConfiguration("sqlserver://localhost/DO40-Tests");
foreach (var type in typeof(FormElement).Assembly.GetTypes())
{
if(typeof(IEntityBase).IsAssignableFrom(type))
domainConfiguration.Types.Register(type);
}
domainConfiguration.UpgradeMode = DomainUpgradeMode.Recreate;
using (var domain = Domain.Build(domainConfiguration))
{
using (var s = domain.OpenSession())
using (s.Activate())
using (var t = Session.Current.OpenTransaction())
{
var n = 10;
//var re = new RegEntity(Guid.NewGuid()) { SysName = "Test" };
//var fs = new FormSetting(Guid.NewGuid()) {};
var e1 = new ExternalDataField(Guid.NewGuid()) { SysName = "ee"};
var eee = new FormElement.TpVisibleEnable(Guid.NewGuid(), e1);
t.Complete();
}
using (var s = domain.OpenSession())
using (s.Activate())
using (var t = Session.Current.OpenTransaction())
{
var e1 = Query.All<ExternalDataField>().Single();
e1.Remove();
t.Complete();
}
}
}
}
/// <summary>
/// Data fields
/// </summary>
/// <revision>$Rev: 20894 $</revision>
public abstract partial class DataFieldBase : FormElement
{
/// <summary>
/// Initializes a new instance of the <see cref="TablePartBase{TOwner}"/> class.
/// </summary>
/// <param name="id">
/// Element identifier
/// </param>
protected DataFieldBase(Guid id)
: base(id)
{
}
/// <summary>
/// Binding expression
/// </summary>
[Field(Length = 4000)]
public string BindingExpression { get; set; }
}
/// <summary>
/// External fields
/// Field, showing external data, not an entity field
/// </summary>
/// <revision>$Rev: 20894 $</revision>
[Serializable]
public partial class ExternalDataField : DataFieldBase
{
/// <summary>
/// Constructer External field
/// </summary>
/// <param name="id">unique log identifier</param>
public ExternalDataField(Guid id)
: base(id)
{
}
/// <summary>
/// System name
/// Short and understandable name used in code
/// </summary>
[Field(Nullable = false)]
public string SysName { get; set; }
}
/// <summary>
/// Depends upon owner
/// Represents an entity which is dependant upon the onwer
/// </summary>
/// <typeparam name="TOwner">Сущность-владелец</typeparam>
public interface IOwned<out TOwner> : IEntityBase
where TOwner : IEntityBase
{
/// <summary>
/// Owner
/// This entity will be removed upon onwer deletion
/// </summary>
[Field(Nullable = false, Indexed = false)]
[Association(OnTargetRemove = OnRemoveAction.Cascade, OnOwnerRemove = OnRemoveAction.Clear)]
TOwner Owner { get; }
}
/// <summary>
/// Form element
/// Base class for all form elements. Contains Form elemnts settings
/// </summary>
/// <revision>$Rev: 20894 $</revision>
[HierarchyRoot(Clustered = false)]
public abstract partial class FormElement : EntityBase
{
/// <summary>
/// Initializes a new instance of the <see cref="TablePartBase{T}"/> class.
/// </summary>
/// <param name="id">
/// Element identifier.
/// </param>
protected FormElement(Guid id)
: base(id)
{
}
/// <summary>
/// Availiablity and Visibility
/// Defines conditions for this element Availiablity and Visibility
/// </summary>
[Association(PairTo = "Owner", OnTargetRemove = OnRemoveAction.Clear, OnOwnerRemove = OnRemoveAction.Cascade)]
[Field]
public EntitySet<TpVisibleEnable> Visibility { get; private set; }
public abstract class TablePartBase<TOwner> : EntityBase, IOwned<TOwner> where TOwner : EntityBase
{
protected TablePartBase(Guid id, TOwner owner)
: base(id)
{
Owner = owner;
}
/// <summary>
/// Owner
/// This entity will be removed upon onwer deletion
/// </summary>
public TOwner Owner { get; private set; }
}
/// <summary>
/// Availiablity and Visibility
/// Availiablity and Visibility conditions for form elements.
/// </summary>
/// <revision>$Rev: 20894 $</revision>
[HierarchyRoot]
[Serializable]
public partial class TpVisibleEnable : TablePartBase<FormElement>
{
/// <summary>
/// Initializes a new instance of the entity
/// </summary>
/// <param name="id">Unique element identifier</param>
/// <param name="owner">
/// Entity owner
/// </param>
public TpVisibleEnable(Guid id, FormElement owner)
: base(id, owner)
{
}
/// <summary>
/// Condition
/// Dynamic Linq Condition
/// </summary>
[Field(Length = 4000)]
public string DynamicLinqExpression { get; set; }
}
}
/// <summary>
/// Base Entity interface
/// </summary>
public interface IEntityBase : IEntity
{
/// <summary>
/// Идентификатор
/// Содержит уникальный Guid элемента.
/// </summary>
[Field]
[Key]
new Guid Id { get; }
}
public abstract class EntityBase : Entity, IEntityBase
{
protected EntityBase(Guid id)
: base(id)
{
}
public Guid Id { get; private set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment