编辑:JSON不完整,不得不削减一些
第一次从服务器查询时,某个实体以某种方式具有“已添加”的 EntityState。我在 DBContextInitializer 中创建了 3 个用户。每次我启动我的应用程序时都会发生这种情况。如果我打电话,它将处于“未更改”状态Manager.rejectChanges()
,但我必须手动执行此操作。
如果我不这样做,并保存另一个实体(可能是团队/订单/订单详细信息),则特定用户将被保存为其原始实体的副本,具有唯一键但具有相同值(如名称等)。如果我可能忘记了什么,我检查了我的代码十几次,但我不会在任何地方调用此用户实体的任何状态更改。
这是Manager.getChanges
(“用户”的实体类型)的打印:
[
[
{
"entityAspect": {
"entityGroup": {
"entityManager": {
"serviceName": "api/Breeze/",
"metadataStore": {
"namingConvention": {
"name": "noChange"
},
"localQueryComparisonOptions": {
"name": "caseInsensitiveSQL",
"isCaseSensitive": false,
"usesSql92CompliantStringComparison": true
},
"dataServices": [
{
"serviceName": "api/Breeze/",
"adapterName": null,
"hasServerMetadata": true
}
],
"_resourceEntityTypeMap": {
"Mvls": "Mvl:#MAHN.Model",
"MvlOps": "MvlOP:#MAHN.Model",
"StatusOps": "StatusOP:#MAHN.Model",
"Teams": "Team:#MAHN.Model",
"TeamLeaders": "TeamLeaders:#MAHN.Model",
"Users": "User:#MAHN.Model",
"TeamUsers": "TeamUsers:#MAHN.Model",
"UserRoles": "UserRoles:#MAHN.Model",
"Roles": "Role:#MAHN.Model",
"TeamRoles": "TeamRoles:#MAHN.Model"
},
"_entityTypeResourceMap": {
"Mvl:#MAHN.Model": "Mvls",
"MvlOP:#MAHN.Model": "MvlOps",
"StatusOP:#MAHN.Model": "StatusOps",
"Team:#MAHN.Model": "Teams",
"TeamLeaders:#MAHN.Model": "TeamLeaders",
"User:#MAHN.Model": "Users",
"TeamUsers:#MAHN.Model": "TeamUsers",
"UserRoles:#MAHN.Model": "UserRoles",
"Role:#MAHN.Model": "Roles",
"TeamRoles:#MAHN.Model": "TeamRoles"
},
"_entityTypeMap": {
"User:#MAHN.Model": {
"name": "User:#MAHN.Model",
"shortName": "User",
"namespace": "MAHN.Model",
"defaultResourceName": "Users",
"dataProperties": [
{
"name": "UserId",
"nameOnServer": "UserId",
"dataType": "Int32",
"isNullable": false,
"defaultValue": 0,
"validators": [
{
"validatorName": "required"
},
{
"validatorName": "int32"
}
],
"isPartOfKey": true
},
{
"name": "UserName",
"nameOnServer": "UserName",
"dataType": "String",
"isNullable": true,
"fixedLength": false,
"validators": [
{
"validatorName": "string"
}
],
"isPartOfKey": false
},
{
"name": "Nachname",
"nameOnServer": "Nachname",
"dataType": "String",
"isNullable": true,
"fixedLength": false,
"validators": [
{
"validatorName": "string"
}
],
"isPartOfKey": false
},
{
"name": "Vorname",
"nameOnServer": "Vorname",
"dataType": "String",
"isNullable": true,
"fixedLength": false,
"validators": [
{
"validatorName": "string"
}
],
"isPartOfKey": false
},
{
"name": "OasisLogin",
"nameOnServer": "OasisLogin",
"dataType": "String",
"isNullable": true,
"fixedLength": false,
"validators": [
{
"validatorName": "string"
}
],
"isPartOfKey": false
}
],
"navigationProperties": [
{
"name": "TeamUsers",
"nameOnServer": "TeamUsers",
"entityTypeName": "TeamUsers:#MAHN.Model",
"isScalar": false,
"associationName": "TeamUsers_User",
"foreignKeyNames": [],
"foreignKeyNamesOnServer": [],
"validators": []
},
{
"name": "UserRoles",
"nameOnServer": "UserRoles",
"entityTypeName": "UserRoles:#MAHN.Model",
"isScalar": false,
"associationName": "UserRoles_User",
"foreignKeyNames": [],
"foreignKeyNamesOnServer": [],
"validators": []
}
],
"autoGeneratedKeyType": "Identity",
"validators": []
},
"Team:#MAHN.Model": {
"entityType": {
"name": "Team:#MAHN.Model",
"shortName": "Team",
"namespace": "MAHN.Model",
"defaultResourceName": "Teams",
"autoGeneratedKeyType": "Identity"
},
"_indexMap": {
"1": 1,
"2": 0,
"3": 2,
"4": 3
},
"_entities": [
{
"entityAspect": {
"entityState": {
"_$typeName": "EntityState",
"name": "Unchanged"
},
"isBeingSaved": false,
"originalValues": {},
"_validationErrors": {},
"validationErrorsChanged": {
"name": "validationErrorsChanged_entityAspect",
"_nextUnsubKey": 1
},
"propertyChanged": {
"name": "propertyChanged_entityAspect",
"_nextUnsubKey": 1
},
"_entityKey": {
"entityType": "Team:#MAHN.Model",
"values": [
2
]
},
"wasLoaded": true
}
},
{
"entityAspect": {
"entityState": {
"_$typeName": "EntityState",
"name": "Unchanged"
},
"isBeingSaved": false,
"originalValues": {},
"_validationErrors": {},
"validationErrorsChanged": {
"name": "validationErrorsChanged_entityAspect",
"_nextUnsubKey": 1
},
"propertyChanged": {
"name": "propertyChanged_entityAspect",
"_nextUnsubKey": 1
},
"_entityKey": {
"entityType": "Team:#MAHN.Model",
"values": [
1
]
},
"wasLoaded": true
}
},
{
"entityAspect": {
"entityState": {
"_$typeName": "EntityState",
"name": "Unchanged"
},
"isBeingSaved": false,
"originalValues": {},
"_validationErrors": {},
"validationErrorsChanged": {
"name": "validationErrorsChanged_entityAspect",
"_nextUnsubKey": 1
},
"propertyChanged": {
"name": "propertyChanged_entityAspect",
"_nextUnsubKey": 1
},
"_entityKey": {
"entityType": "Team:#MAHN.Model",
"values": [
3
]
},
"wasLoaded": true
}
},
{
"entityAspect": {
"entityState": {
"_$typeName": "EntityState",
"name": "Unchanged"
},
"isBeingSaved": false,
"originalValues": {},
"_validationErrors": {},
"validationErrorsChanged": {
"name": "validationErrorsChanged_entityAspect",
"_nextUnsubKey": 1
},
"propertyChanged": {
"name": "propertyChanged_entityAspect",
"_nextUnsubKey": 1
},
"_entityKey": {
"entityType": "Team:#MAHN.Model",
"values": [
4
]
},
"wasLoaded": true
}
}
],
"_emptyIndexes": []
},
"TeamLeaders:#MAHN.Model": {
"entityType": {
"name": "TeamLeaders:#MAHN.Model",
"shortName": "TeamLeaders",
"namespace": "MAHN.Model",
"defaultResourceName": "TeamLeaders",
"autoGeneratedKeyType": "Identity"
},
"_indexMap": {
"1": 0
},
"_entities": [
{
"entityAspect": {
"entityState": {
"_$typeName": "EntityState",
"name": "Unchanged"
},
"isBeingSaved": false,
"originalValues": {},
"_validationErrors": {},
"validationErrorsChanged": {
"name": "validationErrorsChanged_entityAspect",
"_nextUnsubKey": 1
},
"propertyChanged": {
"name": "propertyChanged_entityAspect",
"_nextUnsubKey": 1
},
"_entityKey": {
"entityType": "TeamLeaders:#MAHN.Model",
"values": [
1
]
},
"wasLoaded": true
}
}
],
"_emptyIndexes": []
}
},
"_unattachedChildrenMap": {
"map": {}
},
"keyGenerator": {
"_tempIdMap": {},
"nextNumber": -1,
"nextNumberIncrement": -1,
"stringPrefix": "K_"
},
"_hasChanges": true
},
"entityType": {
"name": "User:#MAHN.Model",
"shortName": "User",
"namespace": "MAHN.Model",
"defaultResourceName": "Users",
"autoGeneratedKeyType": "Identity"
},
"_indexMap": {
"1": 2,
"2": 0,
"3": 1
},
"_entities": [
{
"entityAspect": {
"entityState": {
"_$typeName": "EntityState",
"name": "Unchanged"
},
"isBeingSaved": false,
"originalValues": {},
"_validationErrors": {},
"validationErrorsChanged": {
"name": "validationErrorsChanged_entityAspect",
"_nextUnsubKey": 1
},
"propertyChanged": {
"name": "propertyChanged_entityAspect",
"_nextUnsubKey": 1
},
"_entityKey": {
"entityType": "User:#MAHN.Model",
"values": [
2
]
},
"wasLoaded": true
}
},
{
"entityAspect": {
"entityState": {
"_$typeName": "EntityState",
"name": "Unchanged"
},
"isBeingSaved": false,
"originalValues": {},
"_validationErrors": {},
"validationErrorsChanged": {
"name": "validationErrorsChanged_entityAspect",
"_nextUnsubKey": 1
},
"propertyChanged": {
"name": "propertyChanged_entityAspect",
"_nextUnsubKey": 1
},
"_entityKey": {
"entityType": "User:#MAHN.Model",
"values": [
3
]
},
"wasLoaded": true
}
},
null
],
"_emptyIndexes": []
},
"entityState": {
"_$typeName": "EntityState",
"name": "Added"
},
"isBeingSaved": false,
"originalValues": {},
"_validationErrors": {},
"validationErrorsChanged": {
"name": "validationErrorsChanged_entityAspect",
"_nextUnsubKey": 1
},
"propertyChanged": {
"name": "propertyChanged_entityAspect",
"_nextUnsubKey": 1
},
"_entityKey": {
"entityType": "User:#MAHN.Model",
"values": [
1
]
},
"wasLoaded": true
}
}
]
]
我无法从中提取很多信息,但我认为这个特殊部分很奇怪。为什么该数组中的第三个对象null
但在该数组之后不久显示为“已添加”状态:
"_entities": [
{
"entityAspect": {
"entityState": {
"_$typeName": "EntityState",
"name": "Unchanged"
},
"isBeingSaved": false,
"originalValues": {},
"_validationErrors": {},
"validationErrorsChanged": {
"name": "validationErrorsChanged_entityAspect",
"_nextUnsubKey": 1
},
"propertyChanged": {
"name": "propertyChanged_entityAspect",
"_nextUnsubKey": 1
},
"_entityKey": {
"entityType": "User:#MAHN.Model",
"values": [
2
]
},
"wasLoaded": true
}
},
{
"entityAspect": {
"entityState": {
"_$typeName": "EntityState",
"name": "Unchanged"
},
"isBeingSaved": false,
"originalValues": {},
"_validationErrors": {},
"validationErrorsChanged": {
"name": "validationErrorsChanged_entityAspect",
"_nextUnsubKey": 1
},
"propertyChanged": {
"name": "propertyChanged_entityAspect",
"_nextUnsubKey": 1
},
"_entityKey": {
"entityType": "User:#MAHN.Model",
"values": [
3
]
},
"wasLoaded": true
}
},
null
],
如果有帮助,我可以提供更多信息。