2
I only had the opportunity to use the EF basically 1x. Therefore, I am with many doubts, even consulting a lot google. I have a client application that will take various data from the logged user’s Facebook...
Playing Json2charp I have the following classes:
public class UserData
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[JsonProperty("id")]
public string idface { get; set; }
public string name { get; set; }
public string birthday { get; set; }
public string email { get; set; }
public Hometown hometown { get; set; }
public Location location { get; set; }
public Events events { get; set; }
public Likes likes { get; set; }
public Age_Range age_range { get; set; }
public string gender { get; set; }
public Picture picture { get; set; }
}
public class Hometown
{
public string id { get; set; }
public string name { get; set; }
}
public class Location
{
public string id { get; set; }
public string name { get; set; }
}
public class Events
{
public Datum[] data { get; set; }
public Paging paging { get; set; }
}
public class Paging
{
public Cursors cursors { get; set; }
public string next { get; set; }
}
public class Cursors
{
public string before { get; set; }
public string after { get; set; }
}
public class Datum
{
public string description { get; set; }
public string name { get; set; }
public DateTime start_time { get; set; }
public Place place { get; set; }
public int attending_count { get; set; }
public string id { get; set; }
public string type { get; set; }
public string rsvp_status { get; set; }
public DateTime end_time { get; set; }
}
public class Place
{
public string name { get; set; }
public LocationEvent location { get; set; }
public string id { get; set; }
}
public class LocationEvent
{
public string city { get; set; }
public string country { get; set; }
public float latitude { get; set; }
public float longitude { get; set; }
public string state { get; set; }
public string street { get; set; }
public string zip { get; set; }
}
public class Likes
{
public Datum1[] data { get; set; }
public Paging paging { get; set; }
}
public class Datum1
{
public string category { get; set; }
public string name { get; set; }
public int fan_count { get; set; }
public string website { get; set; }
public string id { get; set; }
public LocationEvent location { get; set; }
public string[] emails { get; set; }
}
public class Age_Range
{
public int min { get; set; }
}
public class Picture
{
public Data data { get; set; }
}
public class Data
{
public bool is_silhouette { get; set; }
public string url { get; set; }
}
When creating a webapi to connect with my Azure SQL, I thought of using EF code first to make my life easier. I then read about Heritages and found the most suitable for my use. However, I believe that my class would have to change to for example:
public class UserData
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[JsonProperty("id")]
public string idface { get; set; }
public string name { get; set; }
public string birthday { get; set; }
public string email { get; set; }
}
public class Hometown : UserData
{
public string id { get; set; }
public string name { get; set; }
}
public class Location : UserData
{
public string id { get; set; }
public string name { get; set; }
}
E assim por diante....
Am I right? Would that be the right one or with you with my informed class first? If yes, which would be the most correct to implement ? TPT ?
I also read about Complex Types.
But the question remains....
In my case Userdata are the main user data...it will always have name... Thanks for the tip... Should I read about Complex Types and make use then ne?
– MC Fer
When you say complex types this refers to: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/complex-type ?
– Gabriel Coletta
https://olavooneto.wordpress.com/2011/07/28/tipos-complexos-com-code-first/
– MC Fer
I understood, it’s always interesting to read about gender issues, but I don’t recommend that you apply the concept of complex types in your example. The first view of the way you mapped it would not be interesting to have a single table for the three entities but two separate ones: Hometown and Location, since we would be breaking the third form of database normalization using a complex type in the example..
– Gabriel Coletta
Now I noticed, you are confusing his example with inheritance, notice that in the example of complex type he does not use inheritance and everything becomes a single entity, in the case of inheritance is a little different.
– Gabriel Coletta
becomes a single entity, but the classes are created the same way as in the client model... which confuses me in which to adopt...
– MC Fer
Let’s go continue this discussion in chat.
– Gabriel Coletta