本文整理汇总了C#中Microsoft.OData.Edm.Library.EdmModel.AddAlternateKeyAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# EdmModel.AddAlternateKeyAnnotation方法的具体用法?C# EdmModel.AddAlternateKeyAnnotation怎么用?C# EdmModel.AddAlternateKeyAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Edm.Library.EdmModel
的用法示例。
在下文中一共展示了EdmModel.AddAlternateKeyAnnotation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEdmModel
public static IEdmModel GetEdmModel()
{
if (_edmModel != null)
{
return _edmModel;
}
EdmModel model = new EdmModel();
// entity type 'Customer' with single alternate keys
EdmEntityType customer = new EdmEntityType("NS", "Customer");
customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
var ssn = customer.AddStructuralProperty("SSN", EdmPrimitiveTypeKind.String);
model.AddAlternateKeyAnnotation(customer, new Dictionary<string, IEdmProperty>
{
{"SSN", ssn}
});
model.AddElement(customer);
// entity type 'Order' with multiple alternate keys
EdmEntityType order = new EdmEntityType("NS", "Order");
order.AddKeys(order.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32));
var orderName = order.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
var orderToken = order.AddStructuralProperty("Token", EdmPrimitiveTypeKind.Guid);
order.AddStructuralProperty("Amount", EdmPrimitiveTypeKind.Int32);
model.AddAlternateKeyAnnotation(order, new Dictionary<string, IEdmProperty>
{
{"Name", orderName}
});
model.AddAlternateKeyAnnotation(order, new Dictionary<string, IEdmProperty>
{
{"Token", orderToken}
});
model.AddElement(order);
// entity type 'Person' with composed alternate keys
EdmEntityType person = new EdmEntityType("NS", "Person");
person.AddKeys(person.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
var country = person.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String);
var passport = person.AddStructuralProperty("Passport", EdmPrimitiveTypeKind.String);
model.AddAlternateKeyAnnotation(person, new Dictionary<string, IEdmProperty>
{
{"Country", country},
{"Passport", passport}
});
model.AddElement(person);
// entity sets
EdmEntityContainer container = new EdmEntityContainer("NS", "Default");
model.AddElement(container);
container.AddEntitySet("Customers", customer);
container.AddEntitySet("Orders", order);
container.AddEntitySet("People", person);
return _edmModel = model;
}
示例2: GetEdmModel
public static IEdmModel GetEdmModel()
{
if (_edmModel != null)
{
return _edmModel;
}
EdmModel model = new EdmModel();
// entity type 'Customer' with single alternate keys
EdmEntityType Language = new EdmEntityType("RoomReservationSystem.Model.DAL", "Language");
Language.AddKeys(Language.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
var langauge_name = Language.AddStructuralProperty("L_Name", EdmPrimitiveTypeKind.String);
model.AddAlternateKeyAnnotation(Language, new Dictionary<string, IEdmProperty>
{
{"L_Name", langauge_name}
});
model.AddElement(Language);
EdmEntityType Billing_Rules = new EdmEntityType("RoomReservationSystem.Model.DAL", "Billing_Rules");
EdmEntityType ApplyAt = new EdmEntityType("RoomReservationSystem.Model.DAL", "ApplyAt");
EdmEntityType Charge = new EdmEntityType("RoomReservationSystem.Model.DAL", "Charge");
EdmEntityType ChargesType = new EdmEntityType("RoomReservationSystem.Model.DAL", "ChargesType");
EdmEntityType BillTimes = new EdmEntityType("RoomReservationSystem.Model.DAL", "BillTime");
EdmEntityType BoardType = new EdmEntityType("RoomReservationSystem.Model.DAL", "BoardType");
EdmEntityType Country = new EdmEntityType("RoomReservationSystem.Model.DAL", "Country");
EdmEntityType Currency = new EdmEntityType("RoomReservationSystem.Model.DAL", "Currency");
EdmEntityType Document_Type = new EdmEntityType("RoomReservationSystem.Model.DAL", "Document_Type");
EdmEntityType MemberType = new EdmEntityType("RoomReservationSystem.Model.DAL", "MemberType");
EdmEntityType RateType = new EdmEntityType("RoomReservationSystem.Model.DAL", "RateType");
EdmEntityType PaymentBy = new EdmEntityType("RoomReservationSystem.Model.DAL", "PaymentBy");
EdmEntityType PaymentModes = new EdmEntityType("RoomReservationSystem.Model.DAL", "PaymentMode");
EdmEntityType ReservationStatusType = new EdmEntityType("RoomReservationSystem.Model.DAL", "ReservationStatusType");
EdmEntityType RoomStatusType = new EdmEntityType("RoomReservationSystem.Model.DAL", "RoomStatusType");
EdmEntityType WaitingListStatus = new EdmEntityType("RoomReservationSystem.Model.DAL", "WaitingListStatus");
// entity sets
EdmEntityContainer container = new EdmEntityContainer("RoomReservationSystem.Model.DAL", "Default");
model.AddElement(container);
container.AddEntitySet("Billing_Rules", Billing_Rules);
container.AddEntitySet("ApplyAts", ApplyAt);
container.AddEntitySet("Charges", Charge);
container.AddEntitySet("ChargesTypes", ChargesType);
container.AddEntitySet("BillTimes", BillTimes);
container.AddEntitySet("BoardTypes", BoardType);
container.AddEntitySet("Countries", Country);
container.AddEntitySet("Currencies", Currency);
container.AddEntitySet("Document_Types", Document_Type);
container.AddEntitySet("Languages", Language);
container.AddEntitySet("MemberTypes", MemberType);
container.AddEntitySet("PaymentBy", PaymentBy);
container.AddEntitySet("RateTypes", PaymentModes);
container.AddEntitySet("PaymentModes", PaymentModes);
container.AddEntitySet("ReservationStatusTypes", ReservationStatusType);
container.AddEntitySet("RoomStatusTypes", RoomStatusType);
container.AddEntitySet("WaitingListStatus", WaitingListStatus);
return _edmModel = model;
}
示例3: GetEdmModel
//.........这里部分代码省略.........
var FullyQualifiedNamespacePerson_MyLions = FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
{
Name = "MyLions",
TargetMultiplicity = EdmMultiplicity.Many,
Target = FullyQualifiedNamespaceLion,
DependentProperties = new List<IEdmStructuralProperty>()
{
FullyQualifiedNamespacePerson_ID
},
PrincipalProperties = new List<IEdmStructuralProperty>()
{
FullyQualifiedNamespaceLion_ID1
}
});
FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(
new EdmNavigationPropertyInfo
{
Name = "MyContainedDog",
TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
Target = FullyQualifiedNamespaceDog,
ContainsTarget = true
});
FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(
new EdmNavigationPropertyInfo
{
Name = "MyContainedChimeras",
TargetMultiplicity = EdmMultiplicity.Many,
Target = FullyQualifiedNamespaceChimera,
ContainsTarget = true
});
var FullyQualifiedNamespacePerson_MyPet2Set = FullyQualifiedNamespacePerson.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "MyPet2Set", TargetMultiplicity = EdmMultiplicity.Many, Target = FullyQualifiedNamespacePet2, });
model.AddAlternateKeyAnnotation(FullyQualifiedNamespacePerson, new Dictionary<string, IEdmProperty>()
{
{"SocialSN", FullyQualifiedNamespacePerson_SSN}
});
model.AddAlternateKeyAnnotation(FullyQualifiedNamespacePerson, new Dictionary<string, IEdmProperty>()
{
{"NameAlias", FullyQualifiedNamespacePerson_Name},
{"FirstNameAlias", FullyQualifiedNamespacePerson_FirstName}
});
model.AddElement(FullyQualifiedNamespacePerson);
FullyQualifiedNamespaceEmployee.AddStructuralProperty("WorkEmail", EdmCoreModel.Instance.GetString(true));
var FullyQualifiedNamespaceEmployee_PaintingsInOffice = FullyQualifiedNamespaceEmployee.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "PaintingsInOffice", TargetMultiplicity = EdmMultiplicity.Many, Target = FullyQualifiedNamespacePainting });
var FullyQualifiedNamespaceEmployee_Manager = FullyQualifiedNamespaceEmployee.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Manager", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = FullyQualifiedNamespaceManager });
var FullyQualifiedNamespaceEmployee_OfficeDog = FullyQualifiedNamespaceDog.AddBidirectionalNavigation
(
new EdmNavigationPropertyInfo()
{
Name = "EmployeeOwner",
TargetMultiplicity = EdmMultiplicity.One,
Target = FullyQualifiedNamespaceEmployee
},
new EdmNavigationPropertyInfo()
{
Name = "OfficeDog",
TargetMultiplicity = EdmMultiplicity.One,
Target = FullyQualifiedNamespaceDog
}
);
model.AddElement(FullyQualifiedNamespaceEmployee);
示例4: TestCommunityAlternateKeysInlineAnnotationOnEntityType
public void TestCommunityAlternateKeysInlineAnnotationOnEntityType()
{
EdmModel model = new EdmModel();
var book = new EdmEntityType("ns", "book");
model.AddElement(book);
var prop1 = book.AddStructuralProperty("prop1", EdmPrimitiveTypeKind.Int32, false);
var prop2 = book.AddStructuralProperty("prop2", EdmPrimitiveTypeKind.Int32, false);
var prop3 = book.AddStructuralProperty("prop3", EdmPrimitiveTypeKind.Int32, false);
var prop4 = book.AddStructuralProperty("prop4", EdmPrimitiveTypeKind.Int32, false);
book.AddKeys(prop1);
model.AddAlternateKeyAnnotation(book, new Dictionary<string, IEdmProperty> { { "s2", prop2 } });
model.AddAlternateKeyAnnotation(book, new Dictionary<string, IEdmProperty> { { "s3", prop3 }, { "s4", prop4 } });
IEnumerable<EdmError> errors;
StringWriter sw = new StringWriter();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = System.Text.Encoding.UTF8;
XmlWriter xw = XmlWriter.Create(sw, settings);
model.TryWriteCsdl(xw, out errors);
xw.Flush();
xw.Close();
var actual = sw.ToString();
const string expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Schema Namespace=""ns"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
<EntityType Name=""book"">
<Key>
<PropertyRef Name=""prop1"" />
</Key>
<Property Name=""prop1"" Type=""Edm.Int32"" Nullable=""false"" />
<Property Name=""prop2"" Type=""Edm.Int32"" Nullable=""false"" />
<Property Name=""prop3"" Type=""Edm.Int32"" Nullable=""false"" />
<Property Name=""prop4"" Type=""Edm.Int32"" Nullable=""false"" />
<Annotation Term=""OData.Community.Keys.V1.AlternateKeys"">
<Collection>
<Record Type=""OData.Community.Keys.V1.AlternateKey"">
<PropertyValue Property=""Key"">
<Collection>
<Record Type=""OData.Community.Keys.V1.PropertyRef"">
<PropertyValue Property=""Alias"" String=""s2"" />
<PropertyValue Property=""Name"" PropertyPath=""prop2"" />
</Record>
</Collection>
</PropertyValue>
</Record>
<Record Type=""OData.Community.Keys.V1.AlternateKey"">
<PropertyValue Property=""Key"">
<Collection>
<Record Type=""OData.Community.Keys.V1.PropertyRef"">
<PropertyValue Property=""Alias"" String=""s3"" />
<PropertyValue Property=""Name"" PropertyPath=""prop3"" />
</Record>
<Record Type=""OData.Community.Keys.V1.PropertyRef"">
<PropertyValue Property=""Alias"" String=""s4"" />
<PropertyValue Property=""Name"" PropertyPath=""prop4"" />
</Record>
</Collection>
</PropertyValue>
</Record>
</Collection>
</Annotation>
</EntityType>
</Schema>";
Assert.AreEqual(expected, actual);
}