等效于Entity Framework 4的ChangeTracker

时间:2018-10-11 03:28:21

标签: c# entity-framework linq

我想使用Entity Framework记录添加的记录

表1

grails {
    plugin {
        springsecurity {
            filterChain {
                chainMap = [
                    [
                            pattern = '/v1/login',
                            filters = 'anonymousAuthenticationFilter'
                    ],
                    [
                            pattern = '/v1/api/**',
                            filters = 'JOINED_FILTERS,-anonymousAuthenticationFilter,-exceptionTranslationFilter,-authenticationProcessingFilter,-securityContextPersistenceFilter,-rememberMeAuthenticationFilter'
                    ]
                ]
            }
            userLookup {
                userLookup = 'User'
                authorityJoinClassName = 'UserRole'
            }
            authority {
                className = 'Role'
            }
            rest {
                token {
                    storage {
                        jwt {
                            secret = "secret"
                        }
                    }
                    validation {
                        enableAnonymousAccess = true
                    }
                }
            }
        }
    }
}
grails.plugin.springsecurity.roleHierarchy = '''
   ROLE_ADMIN > ROLE_USER
'''

grails.plugin.databasemigration.updateOnStartFileName = 'changelog.groovy'

grails.gorm.failOnError = true
grails.gorm.default.mapping = {
    id generator = 'identity'
}

dataSource {
    pooled = true
    jmxExport = true
    driverClassName = "org.h2.Driver"
//    dialect = "hibernate.MyPostgreSQLDialect"
    username = "sa"
    password = ''

    properties {
        jmxEnabled = true
        initialSize = 5
        maxActive = 50
        minIdle = 5
        maxIdle = 25
        maxWait = 10000
        maxAge = 600000
        timeBetweenEvictionRunsMillis = 5000
        minEvictableIdleTimeMillis = 60000
        validationQuery = "SELECT 1"
        validationQueryTimeout = 3
        validationInterval = 15000
        testOnBorrow = true
        testWhileIdle = true
        testOnReturn = false
        jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
        defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
    }
}

environments {
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
        }
    }

    development {
        dataSource {
            dbCreate = ""
            driverClassName = "org.postgresql.Driver"
            url = "jdbc:postgresql://localhost:5432/priz"
            username = "postgres"
            password = "postgres"
            logSql = false
        }
    }

    production {
        dataSource {
            dbCreate = ""
            pooled = true
            url = System.getenv('PRIZ_DATABASE_URL')
            driverClassName = "org.postgresql.Driver"
            username = System.getenv('PRIZ_DATABASE_USER')
            password = System.getenv('PRIZ_DATABASE_PASSWORD')
            logSql = false
            properties {
                jmxEnabled = true
                initialSize = 5
                maxActive = 50
                minIdle = 5
                maxIdle = 25
                maxWait = 10000
                maxAge = 600000
                timeBetweenEvictionRunsMillis = 5000
                minEvictableIdleTimeMillis = 60000
                validationQuery = "SELECT 1"
                validationQueryTimeout = 3
                validationInterval = 15000
                testOnBorrow = true
                testWhileIdle = true
                testOnReturn = false
                jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
                defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
            }
        }
    }
}

priz {
    auth0 {
        domain = "https://priz-dev.auth0.com"
        cache {
            size = 5
            expiresIn = 10
        }
        rateLimit {
            bucketSize = 10
            refillRate = 1
        }

        api {
            domain = "priz-dev.auth0.com"
            clientId = "secret"
            clientSecret = "secret"
        }
    }
}

保存代码

CatID | Col1 | Col2 | Col3 | Col4 |
----------------------------------
1     | a    | b    | c    | d    |
----------------------------------

用于保存审核的虚拟代码

var context = new DBEntities();
Table1 obj1 = new Table1{
Col1 = "a", Col2 = "b"
};
context.Table1.AddObject(obj1)
context.SaveChanges();

我如何在EF4中做到这一点?

0 个答案:

没有答案