本文整理汇总了C#中EntityKey类的典型用法代码示例。如果您正苦于以下问题:C# EntityKey类的具体用法?C# EntityKey怎么用?C# EntityKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EntityKey类属于命名空间,在下文中一共展示了EntityKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Resolve
public EntityError Resolve(EntityManager em) {
IsServerError = true;
try {
EntityType entityType = null;
if (EntityTypeName != null) {
var stName = TypeNameInfo.FromClrTypeName(EntityTypeName).ToClient(em.MetadataStore).StructuralTypeName;
entityType = em.MetadataStore.GetEntityType(stName);
var ek = new EntityKey(entityType, KeyValues);
Entity = em.GetEntityByKey(ek);
}
if (entityType != null) {
if (PropertyName != null) {
Property = entityType.Properties.FirstOrDefault(p => p.NameOnServer == PropertyName);
if (Property != null) {
PropertyName = Property.Name;
}
}
var vc = new ValidationContext(this.Entity);
vc.Property = Property;
var veKey = (ErrorName ?? ErrorMessage) + (PropertyName ?? "");
var ve = new ValidationError(null, vc, ErrorMessage, veKey);
ve.IsServerError = true;
this.Entity.EntityAspect.ValidationErrors.Add(ve);
}
} catch (Exception e) {
ErrorMessage = ( ErrorMessage ?? "") + ": Unable to Resolve this error: " + e.Message;
}
return this;
}
示例2: EnviarCorreoUsuarioNuevo
/// <summary>
/// Envia correo de usuario nuevo.
/// </summary>
/// <param name="USR_USERNAME"></param>
/// <param name="USR_PASSWORD"></param>
/// <param name="Configuracion"></param>
public static void EnviarCorreoUsuarioNuevo(string USR_USERNAME, string USR_PASSWORD, XmlDocument Configuracion)
{
try
{
UsuarioLogic usuariologica = new UsuarioLogic();
usuario user = usuariologica.GetUsuario(USR_USERNAME);
string mailto = user.USR_CORREO;
string nombre = user.USR_NOMBRE + " " + user.USR_APELLIDO;
string subject = "";
string message = "";
using (var db = new colinasEntities())
{
EntityKey k = new EntityKey("colinasEntities.plantillas_notificaciones", "PLANTILLAS_LLAVE", "USUARIONUEVO");
var pl = db.GetObjectByKey(k);
plantilla_notificacion plantilla = (plantilla_notificacion)pl;
subject = plantilla.PLANTILLAS_ASUNTO;
message = plantilla.PLANTILLAS_MENSAJE;
}
message = message.Replace("{NOMBRE}", nombre);
message = message.Replace("{USUARIO}", USR_USERNAME);
message = message.Replace("{CONTRASEÑA}", USR_PASSWORD);
EnviarCorreo(mailto, subject, message, Configuracion);
}
catch (Exception ex)
{
log.Fatal("Error fatal al enviar correo de usuario nuevo.", ex);
throw;
}
}
示例3: ApplyChanges
public void ApplyChanges(MappingSet mappingSet, EntityKey key)
{
// Create new Component
var component = existingSpecToUse.CreateImplementedComponentFor(key.Parent, newComponentName);
// Set mapped column on the new Component's properties.
foreach(var pair in propertyMappings)
{
var newProperty = component.GetProperty(pair.Key);
var oldProperty = key.Properties.FirstOrDefault(p => p.Name == pair.Value);
if(oldProperty == null)
{
// Something went horribly wrong. We have a Property that has been mapped,
// but it doesn't actually exist. I am chosing to ignore this here, but log it.
log.ErrorFormat("Property {0} was mapped in the ConvertKeyToComponent wizard, but doesn't actually exist in the model.", pair.Value);
continue;
}
newProperty.SetMappedColumn(oldProperty.MappedColumn());
}
// Delete existing properties if needed.
if(deleteExistingProperties)
{
foreach(var property in key.Properties.ToList())
{
property.DeleteSelf();
}
}
key.Component = component;
}
示例4: LookupByPrimaryKey
public EntityRecord LookupByPrimaryKey(EntityKey primaryKey)
{
EntityRecord rec;
if (RecordsByPrimaryKey.TryGetValue(primaryKey, out rec))
return rec;
return null;
}
示例5: AddOrUpdate
public void AddOrUpdate(System.Globalization.CultureInfo culture, EntityKey key, IEnumerable<PropertyTranslation> propertyTranslations)
{
using (var db = new MultilingualDbContext(InstanceName))
{
var entry = db.Translations.Find(GetUnderlyingEntityKey(culture.Name, key));
if (entry == null)
{
entry = new EntityTranslationDbEntry
{
Culture = culture.Name,
EntityType = key.EntityType.Name,
EntityKey = key.Value.ToString()
};
entry.Properties = JsonConvert.SerializeObject(propertyTranslations);
db.Translations.Add(entry);
}
else
{
entry.Properties = JsonConvert.SerializeObject(propertyTranslations);
entry.IsOutOfDate = false;
}
db.SaveChanges();
Event.Raise(new TranslationUpdated(key, propertyTranslations, culture), GetInstance());
}
}
示例6: Main
static void Main(string[] args)
{
using (VS2010Entities ie = new VS2010Entities())
{
EntityKey ek = new EntityKey("VS2010Entities.PESSOA", "COD_PESSOA", 8);
PESSOA p = (PESSOA)ie.GetObjectByKey(ek);
if (p != null)
p.NOME_PESSOA = "EMA FROST";
foreach (var item in ie.PESSOA)
{
Console.WriteLine(item.NOME_PESSOA);
}
Console.WriteLine("------------------------");
ie.SaveChanges();
foreach (var item in ie.PESSOA)
{
Console.WriteLine(item.NOME_PESSOA);
}
Console.ReadKey();
}
}
示例7: BriefView
public BriefView(int id, bool w)
{
obj = new TravelDAL.Tour();
using (var context = new TravelDBEntities())
{
EntityKey key = new EntityKey("TravelDBEntities.Tour", "IDTour", id);
obj = (TravelDAL.Tour)context.GetObjectByKey(key);
if (obj != null)
{
tourname = obj.Name;
addinfo = obj.AdditionalInfo;
if (addinfo.Length > 120) addinfo = addinfo.Substring(0, 120);
addinfo += "...";
minprice = obj.MinimalPrice.ToString();
avgprice = obj.AveragePrice.ToString();
rating = obj.AverageMark.ToString();
wide = w;
foreach (TravelDAL.Country m in obj.Country)
{
countrynames += m.Name;
countrynames += " ";
}
}
}
}
示例8: RemoveByID
/// <summary>
/// Removes the Category by ID.
/// </summary>
/// <param name="categoryID">The category ID.</param>
public static void RemoveByID(int categoryID)
{
object categoryForDeletion;
EntityKey categoryKey = new EntityKey("WebCalendarEntities.Categories", "ID", categoryID);
if (db.TryGetObjectByKey(categoryKey, out categoryForDeletion))
{
try
{
db.DeleteObject(categoryForDeletion);
db.SaveChanges();
}
catch (OptimisticConcurrencyException ex)
{
throw new InvalidOperationException(string.Format(
"The Category with an ID of '{0}' could not be deleted.\n" +
"Make sure that any related objects are already deleted.\n",
categoryKey.EntityKeyValues[0].Value), ex);
}
}
else
{
throw new InvalidOperationException(string.Format(
"The Category with an ID of '{0}' could not be found.\n" +
"Make sure that Category exists.\n",
categoryKey.EntityKeyValues[0].Value));
}
}
示例9: CreateConceptualNullKey
/// <summary>
/// Creates an EntityKey that represents a Conceptual Null
/// </summary>
/// <param name="originalKey">An EntityKey representing the existing FK values that could not be nulled</param>
/// <returns>EntityKey marked as a conceptual null with the FK values from the original key</returns>
public static EntityKey CreateConceptualNullKey(EntityKey originalKey)
{
Debug.Assert(originalKey != null, "Original key can not be null");
//Conceptual nulls have special entity set name and a copy of the previous values
EntityKey nullKey = new EntityKey(s_NullForeignKey, originalKey.EntityKeyValues);
return nullKey;
}
示例10: CreateConceptualNullKey
/// <summary>
/// Creates an EntityKey that represents a Conceptual Null
/// </summary>
/// <param name="originalKey"> An EntityKey representing the existing FK values that could not be nulled </param>
/// <returns> EntityKey marked as a conceptual null with the FK values from the original key </returns>
public static EntityKey CreateConceptualNullKey(EntityKey originalKey)
{
DebugCheck.NotNull(originalKey);
//Conceptual nulls have special entity set name and a copy of the previous values
var nullKey = new EntityKey(s_NullForeignKey, originalKey.EntityKeyValues);
return nullKey;
}
示例11: AddEntityToIndex
public void AddEntityToIndex(EntityKey entityKey, Document doc)
{
// when creating a projection index, the entity key should not be passed
Debug.Assert(entityKey == null);
// adding document to index
this._index.AddEntity(doc);
}
示例12: Dump
/// <summary>
/// Private extension method for ObjectStateManager class
/// Dump all tracking info to a string
/// </summary>
/// <param name="manager">ObjectStateManager</param>
/// <param name="objectStateEntries">Collection of ObjectStateEntries. If null, then all entities will be displayed</param>
/// <param name="entityKey">EntityKey of given entity. If null, then all entities will be displayed</param>
/// <param name="asHtml">Output string as HTML</param>
/// <returns>String with tracking info about entries</returns>
private static string Dump(
ObjectStateManager manager,
IEnumerable<ObjectStateEntry> objectStateEntries,
EntityKey entityKey,
bool asHtml)
{
StringBuilder dump = new StringBuilder();
if (entityKey != null)
{
objectStateEntries = new List<ObjectStateEntry>();
(objectStateEntries as List<ObjectStateEntry>).Add(manager.GetObjectStateEntry(entityKey));
}
else if (objectStateEntries == null)
{
objectStateEntries = manager.GetObjectStateEntries(~EntityState.Detached);
}
dump.AppendFormat("ObjectStateManager entries : # {0}\n", objectStateEntries.Count());
foreach (var entry in objectStateEntries)
{
dump.Append(ObjectStateEntryToString(entry));
if (entry.State == EntityState.Added)
{
for (int i = 0; i < entry.CurrentValues.FieldCount; i++)
{
dump.AppendFormat("\n\t- {0} = {1}",
entry.CurrentValues.GetName(i),
ObjectToString(entry.CurrentValues[i]));
}
}
else if (entry.State == EntityState.Modified)
{
foreach (string prop in entry.GetModifiedProperties())
{
dump.AppendFormat("\n\t- {0} : {1} -> {2}",
prop,
ObjectToString(entry.OriginalValues[prop]),
ObjectToString(entry.CurrentValues[prop]));
}
}
}
if (asHtml)
{
dump.Replace("\n", "<br />");
dump.Replace("\t", " ");
}
else
{
dump.Replace("<b>", "");
dump.Replace("</b>", "");
}
return dump.ToString();
}
示例13: EntityRecordInfo
/// <summary>
///
/// </summary>
/// <param name="metadata"></param>
/// <param name="memberInfo"></param>
/// <param name="entityKey"></param>
public EntityRecordInfo(EntityType metadata, IEnumerable<EdmMember> memberInfo, EntityKey entityKey, EntitySet entitySet)
: base(TypeUsage.Create(metadata), memberInfo) {
EntityUtil.CheckArgumentNull<EntityKey>(entityKey, "entityKey");
EntityUtil.CheckArgumentNull(entitySet, "entitySet");
_entityKey = entityKey;
_entitySet = entitySet;
ValidateEntityType(entitySet);
}
示例14: RelationshipChange
public RelationshipChange(EntityKey sourceKey, EntityKey targetKey, object source, object target, EntitySetBase entitySet, EntityState state)
{
_sourceKey = sourceKey;
_targetKey = targetKey;
_source = source;
_target = target;
_entitySet = entitySet;
_state = state;
}
示例15: ManagementObjectsViewModel
public ManagementObjectsViewModel()
{
using (var context = new MCDatabaseModelContainer())
{
var key = new EntityKey();
context.ObjectStateManager.GetObjectStateEntry(key);
Buildings = context.Buildings.ToList();
}
}