WCF Odata Entity Framework Relationship Names - wcf

I'm having an issue with EF code first and Odata.
If I navigate to the metadata then I find that all of my relationships are defined like this:
<NavigationProperty Name="Jobs" ToRole="Jobs" FromRole="Applicant" Relationship=".Applicant_Jobs"/>
Notice the full stop before the relationship name?
This stops me from adding a service reference to a Console Application. It gives a custom tool error:
Schema specified is not valid. Errors: The relationship attribute is invalid - The value '.Applicant_Jobs' is invalid according to its datatype.
My data contract is defined here:
[DataContract]
public class Applicant
{
[DataMember]
public int ID { get; set; }
[DataMember]
public string Forename { get; set; }
[DataMember]
public string Surname { get; set; }
[DataMember]
public string EmailAddress { get; set; }
[DataMember]
public string PassPhrase { get; set; }
[DataMember]
public string City { get; set; }
[DataMember]
public string County { get; set; }
[DataMember]
public string Country { get; set; }
[DataMember]
public DateTime CreationDate { get; set; }
[DataMember]
public ICollection<Job> Jobs { get; set; }
}
[DataContract]
public class Job
{
[DataMember]
public Applicant Applicant { get; set; }
[DataMember]
public JobStatus JobStatus { get; set; }
[DataMember]
public int ID { get; set; }
[DataMember]
[ForeignKey("Applicant")]
public int ApplicantID { get; set; }
[DataMember]
[ForeignKey("JobStatus")]
public int JobStatusID { get; set; }
[DataMember]
public string JobTitle { get; set; }
[DataMember]
public string WebsiteURL { get; set; }
[DataMember]
public string Reference { get; set; }
[DataMember]
public string Location { get; set; }
[DataMember]
public string Salary { get; set; }
[DataMember]
public string ContactName { get; set; }
[DataMember]
public string ContactEmail { get; set; }
[DataMember]
public string ContactPhone { get; set; }
[DataMember]
public string Pros { get; set; }
[DataMember]
public string Cons { get; set; }
[DataMember]
public string GeneralNotes { get; set; }
[DataMember]
public DateTime CreationDate { get; set; }
[DataMember]
public bool Archived { get; set; }
[DataMember]
public ICollection<JobProgression> JobProgress { get; set; }
}
As you can see, I'm not putting a full stop anywhere, but for some reason one is generated for each relationship in my model, meaning the custom tool fails.

It turns out the contract needs to be in a namespace. That's what the provider was trying to put in front of the dot.

Related

How to ignore nested models in Swagger (ASP.Net Core 3.1)?

I have a complex model with multiple levels, i am using Swashbuckle.
how can I ignore related models in swagger UI? and show just the first level of the model?
See the below example, I want to ignore all relations like JobTitleVM and ICollection.
public class UserVM
{
public int Id { get; set; }
public Guid Guid { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Token { get; set; }
public string Avatar { get; set; }
public int IsActive { get; set; }
public int JobTitleId { get; set; }
public JobTitleVM JobTitle { get; set; }
public int UserStatusId { get; set; }
public UserStatusVM UserStatus { get; set; }
public virtual ICollection<UserStepsVM> UserSteps { get; set; } = new List<UserStepsVM>();
}

Unable to determine the principal end of an association , One to One relation of SQL

This is my error :
Unable to determine the principal end of an association between the types 'SANTEK.Web.Models.SantekOrder' and 'SANTEK.Web.Models.OrderMoneySum'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
What is my mistake logically ?? I mean to build one-to-one relation.
My model classes are here :
[Table("Orders")]
public class SantekOrder
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int SantekOrderId { get; set; }
[Required, StringLength(25)]
[DisplayName("Çatdırılacaq şəxs")]
public string DelivaryManName { get; set; }
[DisplayName("Çatdırılacaq şəxs istifadəçidir?")]
public bool DeliveryManIsUser { get; set; }
[Required, StringLength(25)]
[DisplayName("Çatdırılacaq şəxs ad və soyadı")]
public string DelivaryManSurname { get; set; }
[Required, StringLength(10)]
[DisplayName("Çatdırılacaq şəxs tefon nömrəsi")]
public string DelivaryManTel { get; set; }
[DisplayName("Çatdırılacaq ünvan istifadəçinin ünvandır?")]
public bool IsUserAddress { get; set; }
[Required, StringLength(150)]
[DisplayName("Çatdırılacaq şəxsin ünvanı?")]
public string DelivaryManAddress { get; set; }
public int SanTekUserId { get; set; }
public int OrderMoneySumId { get; set; }
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy-hh-mm-ss}",
ApplyFormatInEditMode = true)]
public DateTime Time { get; set; }
[ForeignKey("SanTekUserId")]
public virtual SanTekUser SanUser { get; set; }
[ForeignKey("SanTekUserId")]
public virtual OrderMoneySum OrderMoneySum { get; set; }
}
This is my OrdersDetail Table to hold all product and their quantity
[Table("OrderedProducts")]
public class OrderMoneySum
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int OrderMoneySumId { get; set; }
[Required]
public int SantekOrderId { get; set; }
[Required]
public int AllProductId { get; set; }
[DisplayName("Miqdarı")]
public int Quantity { get; set; }
[ForeignKey("SantekOrderId")]
public virtual SantekOrder SantekOrder { get; set; }
[ForeignKey("SantekOrderId")]
public virtual AllProduct AllProduct { get; set; }
}

Can I put all my DataContract and DataMember on an interface and them implement that?

So, I've been looking at all kinds of examples of a WCF class that is to be serialized. I'd like to define all my DataContracts and DataMembers in interfaces and then allow implementation that suits the environment. Is this possible, and if so, are there drawbacks to this approach?
[DataContract]
public class Contact
{
[DataMember]
public int Roll { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Address { get; set; }
[DataMember]
public int Age { get; set; }
}
Can instead do this:
[DataContract]
public interface IContact
{
[DataMember]
int Roll { get; set; }
[DataMember]
string Name { get; set; }
[DataMember]
string Address { get; set; }
[DataMember]
int Age { get; set; }
}
public class Contact :IContact
{
public int Roll { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
}

The ForeignKeyAttribute on property 'FontNameId' on type 'ConferenceManagementSystem.Models.FontName' is not valid

New to the website here, and I had tried several solutions which solved similar problems but to no avail, so would really appreciate for some help.
The error:
The ForeignKeyAttribute on property 'FontNameId' on type 'ConferenceManagementSystem.Models.FontName' is not valid. The navigation property 'AbstractFileFormat' was not found on the dependent type 'ConferenceManagementSystem.Models.FontName'. The Name value should be a valid navigation property name.
The code snippet:
namespace ConferenceManagementSystem.Models
{
[Table("AbstractFileFormat")]
public class AbstractFileFormat
{
[Key]
public int AbstractFileFormatId { get; set; }
[Required]
public string Title_HorizontalAlignment { get; set; }
[Required]
[ForeignKey("FontNameId")]
public int Title_FontName { get; set; }
[Required]
public string Title_FontSize { get; set; }
[Required]
public bool Title_Bold { get; set; }
[Required]
public bool Title_Italic{ get; set; }
[Required]
public string Name_HorizontalAlignment { get; set; }
[Required]
[ForeignKey("FontNameId")]
public int Name_FontName { get; set; }
[Required]
public string Name_FontSize { get; set; }
[Required]
public bool Name_Bold { get; set; }
[Required]
public bool Name_Italic { get; set; }
[Required]
public string Address_HorizontalAlignment { get; set; }
[Required]
[ForeignKey("FontNameId")]
public int Address_FontName { get; set; }
[Required]
public string Address_FontSize { get; set; }
[Required]
public bool Address_Bold { get; set; }
[Required]
public bool Address_Italic { get; set; }
[Required]
public string Email_HorizontalAlignment { get; set; }
[Required]
[ForeignKey("FontNameId")]
public int Email_FontName { get; set; }
[Required]
public string Email_FontSize { get; set; }
[Required]
public bool Email_Bold { get; set; }
[Required]
public bool Email_Italic { get; set; }
public float LineSpacing { get; set; }
public int ConferenceId { get; set; }
public virtual Conference Conference { get; set; }
public virtual FontName FontName { get; set; }
}
}
Second snippet:
namespace ConferenceManagementSystem.Models
{
[Table("FontName")]
public class FontName
{
[Key]
public int FontNameId { get; set; }
public int Name { get; set; }
public virtual ICollection<AbstractFileFormat> AbstractFileFormats { get; set; }
}
}
I had the same issue, and I did this, and it worked.
Add another property in AbstractFileFormat class, that corresponds to the Foreign Key in the AbstractFileFormat table. i.e. the field that points to the FontNameId field in the FontName table. Something like this:
public int FontNameId { get; set; }
[Required]
[ForeignKey("FontNameId")]
public int Email_FontName { get; set; }

Adding checkboxes in MVC4

I have searched and was unable to find a way to display checkboxes in my view. I have 2 entities: Assignment and Chore which is a one-to-many relationship (one assignment, many chores)
public class Chore
{
public System.Guid ChoreId { get; set; }
public string ChoreName { get; set; }
public string Description { get; set; }
public int PointValue { get; set; }
}
public class Assignment
{
public int AssignmentId { get; set; }
public System.Guid RecipientId { get; set; }
public Nullable<bool> Completed { get; set; }
public System.DateTime AssignedDate { get; set; }
public Nullable<System.DateTime> CompletedDate { get; set; }
public virtual IEnumerable<Chore> Chores { get; set; }
}
How can I display a list of all possible chores That I can select whenever I want to create an assignment?