Changing to ZeroOne

11 posts, 0 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 10 Jan 2011 Link to this post

    When I use the association to link entities onto a View it creates the association properties and collections

    When I change the type of the association from Many to lets say ZeroOne, shouldn't it update the property to just be a sinlge instead of the IList collection?
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 11 Jan 2011 Link to this post

    Hello Steve,

    When you are working with associations that are defined between classes mapped to tables (or views) and those tables exist in the model, changing the multiplicity of an association end (for example from m:n to 1:n) is done from the Relationships page of the Details Editor. If you have a join table association (m:n) you can switch to foreign key association (1:n) by disabling the Use Join Table checkbox, then configure the foreign/primary key columns of the association. Performing these actions will also affect the type of your navigation properties automatically.

    The SourceMultiplicity and TargetMultiplicity properties that you see for associations are only respected when the association is default mapped, i.e. when the classes on the two association ends are not mapped to tables. This may happen in case of using forward mapping. Then the Details Editor is empty (as there are no real columns to show) and you can change the multiplicity of the association ends from the Properties pane. The types of the navigation members will be changed automatically if needed.
    Hope that helps.

    Kind regards,
    Alexander
    the Telerik team
    Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
  3. DevCraft banner
  4. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 11 Jan 2011 Link to this post

    You know what...I've actually LOST the window which shows the relationships, I think I closed it by accident, and I have no idea how to re-enable it...

    **EDIT**
    Not the VS properties, or the domain model view, the helper window which shows the mappings from key to key
  5. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 12 Jan 2011 Link to this post

    Hi Steve,

    You can open the Details Editor from View -> Other Windows -> Entity Diagrams Details Editor. The Model Schema Explorer entry should be available there as well.

    Regards,
    Alexander
    the Telerik team
    Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
  6. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 12 Jan 2011 Link to this post

    AHHH, yes, I was looking for the "Mapping Details Editor"

    Thanks much
  7. Dave
    Dave avatar
    4 posts
    Member since:
    May 2013

    Posted 14 May 2013 Link to this post

    Is the Relationships page no longer available on the Mapping Details Editor?  and if so, how do I get it to appear?
  8. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 17 May 2013 Link to this post

    Hi Dave,

    Since version Q1 2011 of OpenAccess ORM, the Relationships page was enhanced with new features that extended the number of scenarios it supports and was renamed to Association Editor.

    Association Editor can be started in the following ways:
    1) If you right-click an existing association and select Edit Association...
    2) If you select an existing association, press F4 to open the Properties window and click the (...) button next to (edit settings) of the Association Settings property
    3) If you select Association from Toolbox and connect two domain classes with it
    4) If you right-click on the surface of Visual Designer and select Add \ Add New Association...

    With the help of Association Editor you can create and tune all types of associations: one-to-one, one-to-many, many-to-many. This set of documentation articles will guide you through the process and the specifics for each association type.

    I hope that helps. If you have additonal questions or experience difficulties with the scenario you implement, do not hesitate to get back to us.


    Kind regards,
    Doroteya
    the Telerik team
    OpenAccess Samples Kit boasts 50+ sample applications providing diverse real-life business solutions. Click to read more and see OpenAccess ORM in action.
  9. Dilshod
    Dilshod avatar
    23 posts
    Member since:
    Feb 2012

    Posted 15 May 2014 Link to this post

    Hi,
    I was facing the same issue. I have two tables: Student and Backpack.
    Student
     - Id (primary key)
     - Name

    Backpack
     - Id (primary key)
     - StuffInside
     - StudentId (not nullable and unique)


    I want one to zero one association from Student to Backpack. When try mapping with Telerik Data Access it puts the association as One To Many. We know that there can not be more than one backpack for each student. Is there way if can change it to One To Zero One? I can't make Backpack Id as a foreign key because of my business logic.
    I am using fluent mapping.

    Thanks,
     
  10. Boyan
    Admin
    Boyan avatar
    100 posts

    Posted 16 May 2014 Link to this post

    Hi Dilshod,

    The recommended approach for mapping one-to-one associations using the Visual Designer is described by this documentation article

     The set-up you described involving creating one-to-one association between columns that are not also primary keys is not supported.
    As an alternative I could suggest you to create one-to-many association between between the ID column of the Student table and the StudentId column of the Backpacks table and adapt your programming implementation for that. You could make the StudentId unique on the database server side. 

    Alternatively, you could use the code-only approach. Once you have created your database schema and created a fluent model, you could modify the mapping so that each Student has a Backpack property (instead of list of Backpacks).

    Do not hesitate to contact us again should you have any further questions. 

    Regards,
    Boyan
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  11. Dilshod
    Dilshod avatar
    23 posts
    Member since:
    Feb 2012

    Posted 19 May 2014 in reply to Boyan Link to this post

    Hi Boyan,
    Thanks for your response. I was doing everything you said above:
    I was using fluent mapping and tried to change the Collection property to reference property. I renamed all the field names in FluentMetadataSource. When I run it I can't see the Backpack when go like this: student.Backpack. it is null, but when I do backpack.Student I can see the student. I am not sure what is wrong with my code.

    Here is my FluentMetaDataSource code:

         public partial class EntitiesModel1FluentMetadataSource : FluentMetadataSource
        {
             
            protected override IList<MappingConfiguration> PrepareMapping()
            {
                List<MappingConfiguration> mappingConfigurations = new List<MappingConfiguration>();
                 
                MappingConfiguration<Student> studentConfiguration = this.GetStudentMappingConfiguration();
                mappingConfigurations.Add(studentConfiguration);
                 
                MappingConfiguration<Backpack> backpackConfiguration = this.GetBackpackMappingConfiguration();
                mappingConfigurations.Add(backpackConfiguration);
                 
                return mappingConfigurations;
            }
             
            protected override void SetContainerSettings(MetadataContainer container)
            {
                container.Name = "EntitiesModel1";
                container.DefaultNamespace = "WpfApplication3";
                container.NameGenerator.RemoveLeadingUnderscores = false;
                container.NameGenerator.SourceStrategy = Telerik.OpenAccess.Metadata.NamingSourceStrategy.Property;
                container.NameGenerator.RemoveCamelCase = false;
            }
            public MappingConfiguration<Student> GetStudentMappingConfiguration()
            {
                MappingConfiguration<Student> configuration = this.GetStudentClassConfiguration();
                this.PrepareStudentPropertyConfigurations(configuration);
                this.PrepareStudentAssociationConfigurations(configuration);
     
                return configuration;
            }
     
            public MappingConfiguration<Student> GetStudentClassConfiguration()
            {
                MappingConfiguration<Student> configuration = new MappingConfiguration<Student>();
                configuration.MapType(x => new { }).WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed).ToTable("Student");
         
                return configuration;
            }
         
            public void PrepareStudentPropertyConfigurations(MappingConfiguration<Student> configuration)
            {
                configuration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Guid).HasFieldName("_id").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("Id").IsNotNullable().HasColumnType("uniqueidentifier").HasPrecision(0).HasScale(0);
                configuration.HasProperty(x => x.Name).HasFieldName("_name").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("Name").IsNullable().HasColumnType("varchar").HasLength(50);
            }
         
            public void PrepareStudentAssociationConfigurations(MappingConfiguration<Student> configuration)
            {
                configuration.HasAssociation(x => x.Backpack).HasFieldName("_backpack").WithOpposite(x => x.Student).ToColumn("StudentId").HasConstraint((y, x) =>  x.StudentId == y.Id ).WithDataAccessKind(DataAccessKind.ReadWrite);
            }
             
            public MappingConfiguration<Backpack> GetBackpackMappingConfiguration()
            {
                MappingConfiguration<Backpack> configuration = this.GetBackpackClassConfiguration();
                this.PrepareBackpackPropertyConfigurations(configuration);
                this.PrepareBackpackAssociationConfigurations(configuration);
     
                return configuration;
            }
     
            public MappingConfiguration<Backpack> GetBackpackClassConfiguration()
            {
                MappingConfiguration<Backpack> configuration = new MappingConfiguration<Backpack>();
                configuration.MapType(x => new { }).WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed).ToTable("Backpack");
         
                return configuration;
            }
         
            public void PrepareBackpackPropertyConfigurations(MappingConfiguration<Backpack> configuration)
            {
                configuration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Guid).HasFieldName("_id").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("Id").IsNotNullable().HasColumnType("uniqueidentifier").HasPrecision(0).HasScale(0);
                configuration.HasProperty(x => x.StuffInside).HasFieldName("_stuffInside").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("StuffInside").IsNullable().HasColumnType("varchar").HasLength(50);
                configuration.HasProperty(x => x.StudentId).HasFieldName("_studentId").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("StudentId").IsNotNullable().HasColumnType("uniqueidentifier").HasPrecision(0).HasScale(0);
            }
         
            public void PrepareBackpackAssociationConfigurations(MappingConfiguration<Backpack> configuration)
            {
                configuration.HasAssociation(x => x.Student).HasFieldName("_student").WithOpposite(x => x.Backpack).ToColumn("StudentId").HasConstraint((x, y) =>  x.StudentId == y.Id ).IsRequired().WithDataAccessKind(DataAccessKind.ReadWrite);
            }
             
        }

    Thanks,
  12. Boyan
    Admin
    Boyan avatar
    100 posts

    Posted 21 May 2014 Link to this post

    Hi Dilshod,

    As I investigate further the issue, I learned that mapping one-to-one association between columns that are not also primary keys is not supported both through the Visual Designer and using Fluent Mapping. Please excuse me for misleading you.

    This means that you need to either use the recommended approach for mapping one-to-one associations demonstrated here, or create and work with one-to-many association instead.

    Regards,
    Boyan
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
Back to Top
DevCraft banner