Click here to Skip to main content
14,542,667 members
   

C#

 
AnswerRe: time requirements in real-times systems? Pin
Richard MacCutchan10-Mar-20 7:02
mveRichard MacCutchan10-Mar-20 7:02 
Questionimport multiple csv files into msql database - C# coding - reg Pin
Member 137889379-Mar-20 7:28
MemberMember 137889379-Mar-20 7:28 
AnswerRe: import multiple csv files into msql database - C# coding - reg Pin
phil.o9-Mar-20 8:25
mvephil.o9-Mar-20 8:25 
QuestionHow to invoke Web API in console or service application? Pin
meeram399-Mar-20 3:38
professionalmeeram399-Mar-20 3:38 
AnswerRe: How to invoke Web API in console or service application? Pin
Richard Deeming9-Mar-20 8:45
mveRichard Deeming9-Mar-20 8:45 
GeneralRe: How to invoke Web API in console or service application? Pin
meeram399-Mar-20 17:48
professionalmeeram399-Mar-20 17:48 
GeneralRe: How to invoke Web API in console or service application? Pin
Richard Deeming10-Mar-20 0:32
mveRichard Deeming10-Mar-20 0:32 
QuestionConverting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 0:00
MemberExoskeletor8-Mar-20 0:00 
<pre>
Im creating a Xamarin.Android app and for database im using sqlite-net. I was trying to create a table with this structure

public class Templates
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public int Category { get; set; }
[TextBlob("imagesBlobbed")]
public List<int> Images { get; set; }
public string imagesBlobbed { get; set; }
}
but i want every time im adding a template to check if it already exist by checking the Images like this:

public static void AddTemplate(SQLiteConnection db, int category, List<int> images)
{
var alreadyExist = db.Table<templates>().Where(record => record.Images == images);

if (alreadyExist?.Count() == 0)
{
var template = new Templates()
{
Category = category,
Images = images,
};
db.InsertWithChildren(template, recursive: true);
}
}
but it's not working and i'm guessing it is not working because you cannot query with parameter "Images", in the database is stored as a blob. So im guessing i have to convert List to something else that is more easily supported in sqlite.

I'm thinking of using sqlite-net-extensions that support one to many relations and do something like this:

[Table("Templates")]
public class Template
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public int Category { get; set; }
[OneToMany]
public TemplateImage Images { get; set; } = new List<int>();
}
[Table("TemplateImages")]
public class TemplateImage
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public int Image1 { get; set; }
public int Image2 { get; set; }
public int Image3 { get; set; }
public int Image4 { get; set; }
public int Image5 { get; set; }
[ForeignKey(typeof(Template))]
public int TemplateId { get; set; }
}
In my application every template has 5 images, but this might change in the future. What is the correct approach according to DB design, to have a TemplateImage object with 5 images or to have only one image for every TemplateImage object like this:

[Table("Templates")]
public class Template
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public int Category { get; set; }
[OneToMany]
public List<templateimage> Images { get; set; } = new List<int>();
}
[Table("TemplateImages")]
public class TemplateImage
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public int Image { get; set; }
[ForeignKey(typeof(Template))]
public int TemplateId { get; set; }
}
Is the second approach slower? Is there any other better way for this?
AnswerRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen8-Mar-20 9:20
professionalEddy Vluggen8-Mar-20 9:20 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 11:23
MemberExoskeletor8-Mar-20 11:23 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Mycroft Holmes8-Mar-20 13:28
professionalMycroft Holmes8-Mar-20 13:28 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 14:20
MemberExoskeletor8-Mar-20 14:20 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Mycroft Holmes8-Mar-20 14:51
professionalMycroft Holmes8-Mar-20 14:51 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 14:54
MemberExoskeletor8-Mar-20 14:54 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 14:56
MemberExoskeletor8-Mar-20 14:56 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Mycroft Holmes8-Mar-20 15:12
professionalMycroft Holmes8-Mar-20 15:12 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 16:02
MemberExoskeletor8-Mar-20 16:02 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen8-Mar-20 21:50
professionalEddy Vluggen8-Mar-20 21:50 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 22:36
MemberExoskeletor8-Mar-20 22:36 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen8-Mar-20 22:44
professionalEddy Vluggen8-Mar-20 22:44 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor8-Mar-20 23:28
MemberExoskeletor8-Mar-20 23:28 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 0:18
professionalEddy Vluggen9-Mar-20 0:18 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 0:21
MemberExoskeletor9-Mar-20 0:21 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Eddy Vluggen9-Mar-20 0:34
professionalEddy Vluggen9-Mar-20 0:34 
GeneralRe: Converting List<int> to List<object> for One to Many relation with sqlite-net-extensions Pin
Exoskeletor9-Mar-20 0:39
MemberExoskeletor9-Mar-20 0:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.