locked
EF Code First Custom Schema Mapping RRS feed

Answers

All replies

  • I might have the answer. Is this correct?

    Protected Overrides Sub OnModelCreating(modelBuilder As System.Data.Entity.DbModelBuilder)
            modelBuilder.Configurations.Add(New ReliefConfiguration)
            'map relief to existing table
            modelBuilder.Entity(Of Relief)().ToTable("tbl_Relief")
    End Sub
    
    Public Class ReliefConfiguration
        Inherits EntityTypeConfiguration(Of Relief)
        Public Sub New()
            [Property](Function(r) r.reliefid).HasColumnName("col_relief_id")
            [Property](Function(r) r.reliefname).HasColumnName("col_relief_name")
        End Sub
        End Class
    
    • Edited by pretzelb Friday, October 7, 2011 6:45 PM typo
    • Marked as answer by Alan_chen Tuesday, October 18, 2011 1:59 AM
    Friday, October 7, 2011 6:43 PM
  • Hi pretzelb,

    Welcome!

    Right! This's Fluent API in Code First: http://blogs.msdn.com/b/adonet/archive/2010/12/06/ef-feature-ctp5-fluent-api-samples.aspx

    You can use try to use Data Annotation to decorate the properties: http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-code-first-walkthrough.aspx

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Giorgi Zautashvili Monday, October 10, 2011 11:49 AM
    • Marked as answer by Alan_chen Tuesday, October 18, 2011 1:58 AM
    Monday, October 10, 2011 1:44 AM
  • Hi,

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, October 14, 2011 1:36 AM