本文整理汇总了C#中ObjectContext.CreateObjectSet方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectContext.CreateObjectSet方法的具体用法?C# ObjectContext.CreateObjectSet怎么用?C# ObjectContext.CreateObjectSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectContext
的用法示例。
在下文中一共展示了ObjectContext.CreateObjectSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindAssociatedOrgUnits
/// <summary>
/// Finds the associated org units.
/// </summary>
/// <param name="objectContext">The object context.</param>
/// <param name="dto">The DTO.</param>
/// <returns>An enumerable of the associated Org Unit IDs</returns>
public static IEnumerable<int> FindAssociatedOrgUnits(ObjectContext objectContext, AssociatedOrgUnitsDto dto)
{
List<int> relatedUnits = new List<int>();
var orgUnitAssociationPublished = objectContext.CreateObjectSet<OrgUnitAssociationPublished>();
var orgUnitPublished = objectContext.CreateObjectSet<OrgUnitPublished>();
if (dto.OrganizationalUnitId.HasValue)
{
var orgUnitIdAsList = new List<int>() { dto.OrganizationalUnitId.Value };
if (dto.DescendantOption != DescendantOption.NoDescendants)
{
var newUnits = GetDescendants(orgUnitIdAsList, dto.DescendantOption, orgUnitAssociationPublished, orgUnitPublished);
AddUnitsToList(ref relatedUnits, newUnits);
}
if (dto.LinkedOption != LinkedOption.NoLinkedUnits)
{
var newUnits = GetLinkedUnits(orgUnitIdAsList, dto.LinkedOption, orgUnitAssociationPublished, orgUnitPublished);
AddUnitsToList(ref relatedUnits, newUnits);
}
//add the current org unit
AddUnitsToList(ref relatedUnits, new List<int> { dto.OrganizationalUnitId.Value });
}
return relatedUnits.ToArray();
}
示例2: GetAllUsers
public List<User> GetAllUsers()
{
using (ObjectContext context = new ObjectContext(_connectionString))
{
return context.CreateObjectSet<User>().ToList();
}
}
示例3: BuildKeywordsWithInternalGenerator
private static Service BuildKeywordsWithInternalGenerator(int serviceId, ObjectContext objectContext)
{
// Fetch service entity
var service = objectContext.CreateObjectSet<Service>().Single(s => s.Id == serviceId);
// Sanitize custom keywords and build generated keywords
var generatedKeywords = new StringBuilder();
var delimiter = Utils.Common.Keywords.KeywordUtils.ResolveKeywordDelimiter(service.CustomKeywords);
service.CustomKeywords = Utils.Common.Keywords.KeywordUtils.SanitizeKeywords(service.CustomKeywords, _excludedWords, delimiter);
// Append custom keywords
if (service.CustomKeywords != null)
generatedKeywords.Append(service.CustomKeywords);
// Append service name
if (service.Name != null)
generatedKeywords.Append(delimiter + service.Name);
// Sanitize and persist keywords
var sanitizedKeywords = Utils.Common.Keywords.KeywordUtils.SanitizeKeywords(generatedKeywords.ToString(), _excludedWords);
service.Keywords = sanitizedKeywords;
return service;
}
示例4: GetPicture
public Picture GetPicture(string src)
{
using (ObjectContext context = new ObjectContext(this._connectionString))
{
return context.CreateObjectSet<Picture>().Single(x=>x.Src == src);
}
}
示例5: BuildKeywordsWithInternalGenerator
private static Event BuildKeywordsWithInternalGenerator(int eventId, ObjectContext objectContext)
{
// Fetch event entity
var eventEntity = objectContext.CreateObjectSet<Event>().Include("EventTopicAssociations.EventTopic").Single(e => e.Id == eventId);
// Sanitize custom keywords and build generated keywords
var generatedKeywords = new StringBuilder();
var delimiter = Utils.Common.Keywords.KeywordUtils.ResolveKeywordDelimiter(eventEntity.CustomKeywords);
eventEntity.CustomKeywords = Utils.Common.Keywords.KeywordUtils.SanitizeKeywords(eventEntity.CustomKeywords, _excludedWords, delimiter);
// Append custom keywords
if (eventEntity.CustomKeywords != null)
generatedKeywords.Append(eventEntity.CustomKeywords);
// Append event topics
if (eventEntity.EventTopicAssociations.Count() > 0)
generatedKeywords.Append(delimiter + string.Join(",", eventEntity.EventTopicAssociations.Select(e => e.EventTopic.Name).ToArray()));
// Sanitize and persist keywords
var sanitizedKeywords = Utils.Common.Keywords.KeywordUtils.SanitizeKeywords(generatedKeywords.ToString(), _excludedWords);
eventEntity.Keywords = sanitizedKeywords;
return eventEntity;
}
示例6: BuildKeywordsWithInternalGenerator
private static OrgUnit BuildKeywordsWithInternalGenerator(int orgUnitId, ObjectContext objectContext)
{
// Fetch orgUnit entity with related data
var orgUnitSet = objectContext.CreateObjectSet<OrgUnit>()
.Include("OrgUnitServices.Service")
.Include("OrgUnitTypeAssociations.OrgUnitType");
var orgUnit = orgUnitSet.Single(o => o.Id == orgUnitId);
// Sanitize custom keywords and build generated keywords
var generatedKeywords = new StringBuilder();
var delimiter = Utils.Common.Keywords.KeywordUtils.ResolveKeywordDelimiter(orgUnit.CustomKeywords);
orgUnit.CustomKeywords = Utils.Common.Keywords.KeywordUtils.SanitizeKeywords(orgUnit.CustomKeywords, _excludedWords, delimiter);
// Append custom keywords
if (orgUnit.CustomKeywords != null)
generatedKeywords.Append(orgUnit.CustomKeywords);
// Append org unit type names
generatedKeywords.Append(delimiter + String.Join(delimiter, orgUnit.OrgUnitTypeAssociations.Select(t => t.OrgUnitType.Name)));
// Append service names
generatedKeywords.Append(delimiter + String.Join(delimiter, orgUnit.OrgUnitServices.Select(s => s.Service.Name)));
// Sanitize and persist keywords
var sanitizedKeywords = Utils.Common.Keywords.KeywordUtils.SanitizeKeywords(generatedKeywords.ToString(), _excludedWords);
orgUnit.Keywords = sanitizedKeywords;
return orgUnit;
}
示例7: GetPersonPageInfo
public PersonPageInfo GetPersonPageInfo()
{
using (ObjectContext context = new ObjectContext(_connectionString))
{
return context.CreateObjectSet<PersonPageInfo>().FirstOrDefault(x => x.Id == 1);
}
}
示例8: GetArticle
public Article GetArticle()
{
using (ObjectContext context = new ObjectContext(_connectionString))
{
return context.CreateObjectSet<Article>().FirstOrDefault(x => x.Id == 1);
}
}
示例9: ValidateUserIntegrationEntity
/// <summary>
/// Validates the user integration entity.
/// </summary>
/// <param name="userIntegration">The user integration.</param>
/// <param name="context">The context.</param>
/// <returns></returns>
public static StatusMessage ValidateUserIntegrationEntity(UserIntegrationDto userIntegration, ObjectContext context)
{
const int maximumExternalIdLength = 50;
const int maximumExternalSystemLength = 500;
if (userIntegration == null)
{
return StatusMessage.MissingData;
}
if (userIntegration.UserId == 0)
{
return StatusMessage.InvalidData;
}
if (string.IsNullOrEmpty(userIntegration.ExternalId) || userIntegration.ExternalId.Length > maximumExternalIdLength)
{
return StatusMessage.InvalidData;
}
if (string.IsNullOrEmpty(userIntegration.ExternalSystem) || userIntegration.ExternalSystem.Length > maximumExternalSystemLength)
{
return StatusMessage.InvalidData;
}
if (context.CreateObjectSet<DAL.UserIntegration>().Count(u => u.UserId == userIntegration.UserId && u.ExternalSystem == userIntegration.ExternalSystem && u.Id != userIntegration.Id) > 0)
{
return StatusMessage.DuplicateData;
}
return StatusMessage.Success;
}
示例10: AddNewUser
public void AddNewUser(string firstname, string surname, string email, string description, string username, string password, byte[] imagebyte, string imgtype)
{
using (ObjectContext context = new ObjectContext(_connectionString))
{
var users = context.CreateObjectSet<User>();
int maxId = users.Any() ? users.Max(x => x.Id) : 1;
int pictureId = _pictureRepository.AddPicture(imagebyte, imgtype, string.Empty);
User newUser = new User()
{
Id = +maxId,
Firstname = firstname,
Surname = surname,
Email = email,
DateRegister = DateTime.Now,
Description = description,
Username = username,
Password = password,
isEnable = true,
isAdmin = false,
PictureId = pictureId
};
users.AddObject(newUser);
context.SaveChanges();
};
}
示例11: CheckUnicueUsername
public bool CheckUnicueUsername(string username)
{
using (ObjectContext context = new ObjectContext(_connectionString))
{
bool isExists = context.CreateObjectSet<User>().Any(x => x.Username == username);
return isExists ? false : true;
}
}
示例12: GetPublished
public List<Article> GetPublished()
{
using (ObjectContext context = new ObjectContext(_connectionString))
{
return context.CreateObjectSet<Article>()
.Where(u => u.Published == true).ToList();
}
}
示例13: CheckUniqueTitle
public bool CheckUniqueTitle(string title)
{
using (ObjectContext context = new ObjectContext(_connectionString))
{
bool isExists = context.CreateObjectSet<Article>().Any(u => u.Title == title);
return !isExists;
};
}
示例14: GetArticleComments
public Comment[] GetArticleComments(int articleId)
{
using (ObjectContext context = new ObjectContext(_connectionString))
{
return context.CreateObjectSet<Comment>()
.Where(u => u.ArticleId == articleId).ToArray();
}
}
示例15: ResolveOrgUnitId
protected static int? ResolveOrgUnitId(ObjectContext context, string internalId, string externalId)
{
int? orgUnitId = null;
if (!string.IsNullOrEmpty(externalId))
{
var mapping = context.CreateObjectSet<DataImportEntityIdMap>().FirstOrDefault(m => m.EntityName == "OrgUnit" && m.ExternalId == externalId);
if (mapping == null)
throw new BusinessException("Unknown OrgUnitExternalId: " + externalId);
orgUnitId = mapping.InternalId;
}
else
{
orgUnitId = GetNullableInt(internalId);
}
if (orgUnitId.HasValue && !context.CreateObjectSet<OrgUnit>().Any(ou => ou.Id == orgUnitId.Value))
throw new BusinessException("Invalid OrgUnitID:" + orgUnitId.Value.ToString(CultureInfo.InvariantCulture));
return orgUnitId;
}