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

Code Only Mapping - Related View

2 Answers 27 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.
Anthony
Top achievements
Rank 1
Anthony asked on 24 Jan 2017, 10:16 AM

Hi

I am using the latest version of Data Access and want to use a database view to display some data, i want this view data to be a collection of a persistent type

ie

Stock
- StockID
- ProductCode
-- vwStock

vwStock (already in database)
- StockID
- BestPrice

So i can perform the below query x => x.Stock.vwStock.BestPrice

I have achieved this in the old days with the visual designer but dont know where to start with code only, i cant see anything in the docs?

2 Answers, 1 is accepted

Sort by
0
Bernd
Top achievements
Rank 2
answered on 24 Jan 2017, 03:13 PM

Hi Anthony.

Set the DataAccessKind in your MetaDataSource. Should look likt this then:

MappingConfiguration<vwStock> configuration = new MappingConfiguration<vwStock>();
            configuration.MapType(x => new { }).WithDataAccessKind(DataAccessKind.ReadOnly);
0
Anthony
Top achievements
Rank 1
answered on 24 Jan 2017, 03:22 PM

Hi

Thanks for the reply, however i am still getting this error?

There is already an object named 'vwBestSaleLotBid' in the database.

Here is my meta declaration?

public partial class MetadataSource
   {
       public MappingConfiguration<vwBestSaleLotBid> GetBestSaleLotBidMappingConfiguration()
       {
           MappingConfiguration<vwBestSaleLotBid> configuration = this.GetBestSaleLotBidClassConfiguration();
           this.PrepareBestSaleLotBidConfigurations(configuration);
           this.OnPrepareBestSaleLotBidConfigurations(configuration);
           return configuration;
       }
 
       public MappingConfiguration<vwBestSaleLotBid> GetBestSaleLotBidClassConfiguration()
       {
           var configuration = new MappingConfiguration<vwBestSaleLotBid>();
           configuration.MapType(x => new { }).WithDataAccessKind(DataAccessKind.ReadOnly);
           return configuration;
       }
 
       public void PrepareBestSaleLotBidConfigurations(MappingConfiguration<vwBestSaleLotBid> configuration)
       {
           configuration.HasProperty(x => x.SaleLotId).IsIdentity().IsNotNullable();
           configuration.HasAssociation(x => x.SaleLot).HasConstraint((x, y) => x.SaleLotId == y.SaleLotId);
       }
 
       partial void OnPrepareBestSaleLotBidConfigurations(MappingConfiguration<vwBestSaleLotBid> configuration);
Tags
Development (API, general questions)
Asked by
Anthony
Top achievements
Rank 1
Answers by
Bernd
Top achievements
Rank 2
Anthony
Top achievements
Rank 1
Share this question
or