Code Only Mapping - Related View

Thread is closed for posting
3 posts, 0 answers
  1. Anthony
    Anthony avatar
    7 posts
    Member since:
    May 2003

    Posted 24 Jan 2017 Link to this post

    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. Bernd
    Bernd avatar
    91 posts
    Member since:
    Feb 2013

    Posted 24 Jan 2017 in reply to Anthony Link to this post

    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);
  3. Anthony
    Anthony avatar
    7 posts
    Member since:
    May 2003

    Posted 24 Jan 2017 Link to this post

    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);
Back to Top