This is a migrated thread and some comments may be shown as answers.

Changing to ZeroOne

10 Answers 89 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 10 Jan 2011, 07:01 PM
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?

10 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 11 Jan 2011, 05:52 PM
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.
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 11 Jan 2011, 05:53 PM
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
0
Alexander
Telerik team
answered on 12 Jan 2011, 02:41 PM
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.
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 12 Jan 2011, 02:42 PM
AHHH, yes, I was looking for the "Mapping Details Editor"

Thanks much
0
Dave
Top achievements
Rank 1
answered on 14 May 2013, 07:35 PM
Is the Relationships page no longer available on the Mapping Details Editor?  and if so, how do I get it to appear?
0
Doroteya
Telerik team
answered on 17 May 2013, 12:46 PM
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.
0
Dilshod
Top achievements
Rank 1
answered on 15 May 2014, 05:20 AM
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,
 
0
Boyan
Telerik team
answered on 16 May 2014, 12:18 PM
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.
 
0
Dilshod
Top achievements
Rank 1
answered on 20 May 2014, 03:41 AM
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,
0
Boyan
Telerik team
answered on 21 May 2014, 01:38 PM
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.
 
Tags
General Discussions
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
Alexander
Telerik team
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Dave
Top achievements
Rank 1
Doroteya
Telerik team
Dilshod
Top achievements
Rank 1
Boyan
Telerik team
Share this question
or