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

Fluent API and database views

3 Answers 80 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marko Gluhak
Top achievements
Rank 1
Marko Gluhak asked on 22 Oct 2015, 08:56 AM

I "upgrade" my project from database first to Fluent and now I have problems with update DB script that wants to CREATE TABLE for all views I have in my application.

This is parts of code for that view.

...
MappingConfiguration<cViewAgeGroupExtended> cviewagegroupextendedConfiguration = this.GetcViewAgeGroupExtendedMappingConfiguration(); mappingConfigurations.Add(cviewagegroupextendedConfiguration);
...

​public MappingConfiguration<cViewAgeGroupExtended> GetcViewAgeGroupExtendedMappingConfiguration() { MappingConfiguration<cViewAgeGroupExtended> configuration = this.GetcViewAgeGroupExtendedClassConfiguration(); this.PreparecViewAgeGroupExtendedPropertyConfigurations(configuration); return configuration; }

 

 public MappingConfiguration<cViewAgeGroupExtended> GetcViewAgeGroupExtendedClassConfiguration() { MappingConfiguration<cViewAgeGroupExtended> configuration = new MappingConfiguration<cViewAgeGroupExtended>(); configuration.MapType(x => new { }).WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed).ToTable("View_AgeGroupExtended"); return configuration; }

 

public void PreparecViewAgeGroupExtendedPropertyConfigurations(MappingConfiguration<cViewAgeGroupExtended> configuration) {             configuration.HasProperty(x => x.IdDisciplineGroup).HasFieldName("_idDisciplineGroup").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("IdDisciplineGroup").IsNotNullable().HasColumnType("int").HasPrecision(0).HasScale(0);             configuration.HasProperty(x => x.IdTournament).HasFieldName("_idTournament").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("IdTournament").IsNotNullable().HasColumnType("int").HasPrecision(0).HasScale(0);             configuration.HasProperty(x => x.DisciplineGroupDesignation).HasFieldName("_disciplineGroupDesignation").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("DisciplineGroupDesignation").IsNotNullable().HasColumnType("nvarchar").HasLength(50);             configuration.HasProperty(x => x.DisciplineGroupDefaultName).HasFieldName("_disciplineGroupDefaultName").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("DisciplineGroupDefaultName").IsNotNullable().HasColumnType("nvarchar").HasLength(255);             configuration.HasProperty(x => x.DisciplineGroupDisplayOrder).HasFieldName("_disciplineGroupDisplayOrder").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("DisciplineGroupDisplayOrder").IsNotNullable().HasColumnType("int").HasPrecision(0).HasScale(0);             configuration.HasProperty(x => x.IdAgeGroup).IsIdentity().HasFieldName("_idAgeGroup").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("IdAgeGroup").IsNotNullable().HasColumnType("int").HasPrecision(0).HasScale(0);             configuration.HasProperty(x => x.Designation).HasFieldName("_designation").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("Designation").IsNotNullable().HasColumnType("varchar").HasLength(50);             configuration.HasProperty(x => x.DefaultName).HasFieldName("_defaultName").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("DefaultName").IsNotNullable().HasColumnType("nvarchar").HasLength(255);             configuration.HasProperty(x => x.IsMale).HasFieldName("_isMale").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("IsMale").IsNotNullable().HasColumnType("bit").HasPrecision(0).HasScale(0);             configuration.HasProperty(x => x.DisplayOrder).HasFieldName("_displayOrder").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("DisplayOrder").IsNotNullable().HasColumnType("int").HasPrecision(0).HasScale(0);             configuration.HasProperty(x => x.ReportGroupingNumber).HasFieldName("_reportGroupingNumber").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("ReportGroupingNumber").IsNotNullable().HasColumnType("int").HasPrecision(0).HasScale(0);             configuration.HasProperty(x => x.ReportGroupingDisplayOrder).HasFieldName("_reportGroupingDisplayOrder").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("ReportGroupingDisplayOrder").IsNotNullable().HasColumnType("int").HasPrecision(0).HasScale(0);             configuration.HasProperty(x => x.FightDuration).HasFieldName("_fightDuration").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("FightDuration").IsNotNullable().HasColumnType("int").HasPrecision(0).HasScale(0);             configuration.HasProperty(x => x.IdStatsCategory).HasFieldName("_idStatsCategory").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("IdStatsCategory").IsNotNullable().HasColumnType("int").HasPrecision(0).HasScale(0); configuration.HasProperty(x => x.MinCompetitorDTBirthday).HasFieldName("_minCompetitorDTBirthday").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("MinCompetitorDTBirthday").IsNullable().HasColumnType("date"); configuration.HasProperty(x => x.MaxCompetitorDTBirthday).HasFieldName("_maxCompetitorDTBirthday").WithDataAccessKind(DataAccessKind.ReadWrite).ToColumn("MaxCompetitorDTBirthday").IsNullable().HasColumnType("date"); }​

When I run application I get error that table View_AgeGroupExtended already exists!

 

3 Answers, 1 is accepted

Sort by
0
Ralph Waldenmaier
Telerik team
answered on 26 Oct 2015, 01:46 PM
Hi Marko,
Thank you for contacting us.
You can avoid the creation of view by specifying the views to not participate in the schema update mechanism. See the following snippet based on the FluentSample-NuGet where I have additionally created a view in the database named ProductView.

MappingConfiguration<ProductView> productViewConfiguration = new MappingConfiguration<ProductView>();
productViewConfiguration.MapType(x => new
{
    ID = x.ID,
    ProductName = x.ProductName
})
.UpdateSchema(false)
.ToTable("ProductView");           
productViewConfiguration.HasProperty(x => x.ID).IsIdentity().WithDataAccessKind(DataAccessKind.ReadOnly);
productViewConfiguration.HasProperty(x => x.ProductName).IsIdentity().WithDataAccessKind(DataAccessKind.ReadOnly);

or using your example


public MappingConfiguration<cViewAgeGroupExtended> GetcViewAgeGroupExtendedClassConfiguration()
{
    MappingConfiguration<cViewAgeGroupExtended> configuration = new MappingConfiguration<cViewAgeGroupExtended>();
    configuration.MapType(x => new { })
        .UpdateSchema(false)
        .WithConcurencyControl(OptimisticConcurrencyControlStrategy.Changed)
        .ToTable("View_AgeGroupExtended"); return configuration;
}

Hence the UpdateSchema(false) tells the configuration to not maintain the objects in the database using the schema update tools.

I hope this information is helpful for you.
Do come back in case you have any other question.


Regards,
Ralph Waldenmaier
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
0
Marko Gluhak
Top achievements
Rank 1
answered on 26 Oct 2015, 04:32 PM

Hi,

 

thank for your solution. If I'm correct it means that for views I have to update code and database object manually? Basically if I understand this, only updatable object from code in DB is Table?

 

Thank you
Marko

0
Ralph Waldenmaier
Telerik team
answered on 27 Oct 2015, 04:01 PM
Hi Marko,
Yes, Views are not managed by Telerik Data Access. They are readonly objects and you need to specify the exclusion for the schema updates as pointed out in my previous message. The same applies to any custom stored procedures, in case you want to use them.

Hope that helps.
Fell free to ask in case you have any other question.

Regards,
Ralph Waldenmaier
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
Development (API, general questions)
Asked by
Marko Gluhak
Top achievements
Rank 1
Answers by
Ralph Waldenmaier
Telerik team
Marko Gluhak
Top achievements
Rank 1
Share this question
or