public void ShouldWriteManyToManyForManyToManyMapping() { var mapping = new ManyToManyMapping(); writer.VerifyXml(mapping) .RootElement.HasName("many-to-many"); }
public void Initialize() { MockChildMapping = new Mock<IChildMapping<ManyToManyItem>>(); MockGridReader = new Mock<IGridReader>(); ManyToManyMapping = new ManyToManyMapping<ParentItem, ManyToManyItem, ManyToManyLinker>(child => child.Id, linker => linker.ChildId, linker => linker.ParentId, (parent, children) => parent.ManyToManyChildren = children.ToList()); }
void InitialiseDefaults(Member member) { mapping.Member = member; mapping.SetDefaultValue(x => x.Name, member.Name); mapping.SetDefaultValue(x => x.TableName, mapping.ContainingEntityType.Name + member.Name); mapping.Key = key = new KeyMapping(); key.AddDefaultColumn(new ColumnMapping { Name = mapping.ContainingEntityType.Name + "_id" }); mapping.Index = index = new IndexMapping(); mapping.Index.As <IndexMapping>(ix => ix.SetDefaultValue(x => x.Type, new TypeReference(KeyType))); if (ValueType.IsSimpleType()) { // value type value (element) mapping.Element = element = new ElementMapping(); element.AddDefaultColumn(new ColumnMapping { Name = "Value" }); element.SetDefaultValue(x => x.Type, new TypeReference(typeof(TValue))); } else { // entity value mapping.Relationship = manyToMany = new ManyToManyMapping(); manyToMany.Class = new TypeReference(ValueType); manyToMany.AddDefaultColumn(new ColumnMapping { Name = ValueType.Name + "_id" }); manyToMany.ParentType = mapping.ContainingEntityType; manyToMany.ChildType = ValueType; } if (KeyType.IsSimpleType()) { mapping.Index.As <IndexMapping>(ix => ix.AddDefaultColumn(new ColumnMapping { Name = "Key" })); } else { mapping.Index.As <IndexMapping>(ix => { ix.IsManyToMany = true; ix.AddDefaultColumn(new ColumnMapping { Name = KeyType.Name + "_id" }); }); } }
public void ShouldWriteColumns() { var container = new XmlWriterContainer(); var mapping = new ManyToManyMapping(); mapping.AddColumn(Layer.Defaults, new ColumnMapping("Column1")); writer = container.Resolve <IXmlWriter <ManyToManyMapping> >(); writer.VerifyXml(mapping) .Element("column").Exists(); }
static void Main(string[] args) { //Map Address to User var userAddressMap = new OneToOneMapping<User, Address>(address => address.Id, user => user.AddressId, (user, address) => user.Address = address); //Map Address to Employer & Employer to User var employerAddressMap = new OneToOneMapping<Employer, Address>(address => address.Id, employer => employer.AddressId, (employer, address) => employer.Address = address); var userEmployerMap = new OneToOneMapping<User, Employer>(employer => employer.Id, user => user.EmployerId, (user, employer) => user.Employer = employer); userEmployerMap.AddMapping(employerAddressMap); //Map Car to user var userCarMap = new ManyToManyMapping<User, Car, UserCar>(car => car.Id, userCar => userCar.CarId, userCar => userCar.UserId, (user, cars) => { foreach (var car in cars) { user.Cars.Add(car); car.Users.Add(user); } }); //User Mapping var userMap = new ParentMapping<User>(user => user.Id); userMap.AddMapping(userAddressMap); userMap.AddMapping(userEmployerMap); userMap.AddMapping(userCarMap); //var dataBroker = new SqlDataBroker(@"Server=(localdb)\ProjectsV12;Database=DemoDatabase;Integrated security=True", new DapperGridReaderFactory()); var gridReaderFactory = new SqlGridReaderFactory(); gridReaderFactory.AddEntityFactory(new AddressFactory()); gridReaderFactory.AddEntityFactory(new CarFactory()); gridReaderFactory.AddEntityFactory(new EmployerFactory()); gridReaderFactory.AddEntityFactory(new UserFactory()); gridReaderFactory.AddEntityFactory(new UserCarFactory()); var dataBroker = new SqlDataBroker(@"Server=(localdb)\ProjectsV12;Database=DemoDatabase;Integrated security=True", gridReaderFactory); dataBroker.AddMapping(userMap); var totalTime = 0L; for (int i = 0; i < 100; i++) { Stopwatch watch = new Stopwatch(); watch.Start(); //var parameterList = new List<IDbParameter>(); //parameterList.Add(new DbParameter("BirthDate", DateTime.Parse("06-01-1975"), DbType.Date)); var users = dataBroker.ExecuteStoredProcedure<User>("dbo.ReadUser"); watch.Stop(); totalTime += watch.ElapsedMilliseconds; } var test = totalTime; }
protected override ICollectionRelationshipMapping GetRelationship() { var mapping = new ManyToManyMapping(relationshipAttributes.CloneInner()) { ContainingEntityType = entity, }; if (isTernary && valueType != null) { mapping.Class = new TypeReference(valueType); } return(mapping); }
private ICollectionRelationshipMapping CreateManyToMany(Member property, Type child, Type parent) { var mapping = new ManyToManyMapping { Class = new TypeReference(property.PropertyType.GetGenericArguments()[0]), ContainingEntityType = parent }; mapping.AddDefaultColumn(new ColumnMapping { Name = child.Name + "_id" }); return(mapping); }
static ICollectionRelationshipMapping CreateManyToMany(Member property, Type child, Type parent) { var mapping = new ManyToManyMapping { ContainingEntityType = parent }; mapping.Set(x => x.Class, Layer.Defaults, new TypeReference(property.PropertyType.GetGenericArguments()[0])); var columnMapping = new ColumnMapping(); columnMapping.Set(x => x.Name, Layer.Defaults, child.Name + "_id"); mapping.AddColumn(Layer.Defaults, columnMapping); return(mapping); }
protected override ICollectionRelationshipMapping GetRelationship() { ManyToManyMapping manyToManyMapping = new ManyToManyMapping(this.relationshipAttributes.Clone()) { ContainingEntityType = this.EntityType }; if (this.isTernary && this.valueType != (Type)null) { manyToManyMapping.Set <TypeReference>((Expression <Func <ManyToManyMapping, TypeReference> >)(x => x.Class), 0, new TypeReference(this.valueType)); } foreach (IFilterMappingProvider filterMappingProvider in (IEnumerable <IFilterMappingProvider>) this.childFilters) { manyToManyMapping.ChildFilters.Add(filterMappingProvider.GetFilterMapping()); } return((ICollectionRelationshipMapping)manyToManyMapping); }
protected ManyToManyPart(Type entity, Member member, Type collectionType) : base(entity, member, collectionType) { this.entity = entity; childType = collectionType; fetch = new FetchTypeExpression <ManyToManyPart <TChild> >(this, value => collectionAttributes.Set(x => x.Fetch, value)); notFound = new NotFoundExpression <ManyToManyPart <TChild> >(this, value => relationshipMapping.NotFound = value); relationshipMapping = new ManyToManyMapping { ContainingEntityType = entity }; relationshipMapping.As <ManyToManyMapping>(x => x.AddDefaultColumn(new ColumnMapping { Name = typeof(TChild).Name + "_id" })); }
protected override ICollectionRelationshipMapping GetRelationship() { var mapping = new ManyToManyMapping(relationshipAttributes.Clone()) { ContainingEntityType = EntityType, }; if (isTernary && valueType != null) { mapping.Set(x => x.Class, Layer.Defaults, new TypeReference(valueType)); } foreach (var filterPart in childFilters) { mapping.ChildFilters.Add(filterPart.GetFilterMapping()); } return(mapping); }
public virtual void ProcessManyToMany(ManyToManyMapping manyToManyMapping) { }
public virtual void Visit(ManyToManyMapping mapping) { }
public ManyToManyInstance(ManyToManyMapping mapping) : base(mapping) { this.mapping = mapping; }
public ManyToManyInspector(ManyToManyMapping mapping) { this.mapping = mapping; mappedProperties.Map(x => x.LazyLoad, x => x.Lazy); }
public void CreateDsl() { mapping = new ManyToManyMapping(); inspector = new ManyToManyInspector(mapping); }
public override void ProcessManyToMany(ManyToManyMapping mapping) { var writer = serviceLocator.GetWriter <ManyToManyMapping>(); document = writer.Write(mapping); }
public ManyToManyBuilder(ManyToManyMapping mapping) { this.mapping = mapping; }