My problem as it is right now. That is, it does not go down to the other table which is courseCategory which is put together with CourseData.
I would therefore like to get hold of courses that have been set up on the single category value.
Let's say that Course did not find anything on any of the others while addressing my category content.
As you can see in the picture here, for example, I just have several right now, but when each course adds a category. and it is not found on any of the others. Well then, search for the single category should take over.
So my problem to make it clear is that it basically does not address the words from SearchWord. As long as there is one or more words that fit, it must address it.
public List<CourseData> GetCourseList(string text)//Undervisning
{
List<CourseData> list = new List<CourseData>();
var dataContent = _dbContext.CourseDataModul
.Where(r => r.Title.Contains(text)
|| r.Deck.Contains(text)
|| r.CourseDataContent.FirstOrDefault(x => x.Title.Contains(text)).Title.Contains(text)
|| r.CourseDataContent.FirstOrDefault(x => x.Deck.Contains(text)).Deck.Contains(text)
|| r.CourseDataContent.FirstOrDefault(x => x.ContentValue.Contains(text)).ContentValue.Contains(text))
.ToList();
foreach (var item in dataContent)
{
list = _dbContext.CourseData
.Where(r => r.Id == item.CourseDataId && r.OpenNow || r.Title.Contains(text) || r.Deck.Contains(text) ||
r.CourseCategori.SearchWord
.Split(new [] {",", ", ", " "}, StringSplitOptions.None) //online undervisning,undervisning,computer undervisning
.Contains(text)).ToList();//undervisning
}
return list;
}
You can see in the code by split that I have commented on some code which should tell what it looks like in the database and that it should for example just be based on "undervisning" only. As I said, it is welcome to address more.
I have looked at these here link:
How can i check and split strings which contains comma,backslash,and(&),hyphen
c# split string only if delimiter found
Best way to check for string in comma-delimited list with .NET?
Update.
After I have updated my code and done like this. Then there will be an error which can be seen here.
public List<CourseData> GetCourseList(string text)//Undervisning
{
List<CourseData> list = new List<CourseData>();
var dataContent = _dbContext.CourseDataModul
.Where(r => r.Title.Contains(text)
|| r.Deck.Contains(text)
|| r.CourseDataContent.Any(x => x.Title.Contains(text))
|| r.CourseDataContent.Any(x => x.Deck.Contains(text))
|| r.CourseDataContent.Any(x => x.ContentValue.Contains(text)))
.ToList();
if (dataContent.Count > 0)
{
foreach (var item in dataContent)
{
list = _dbContext.CourseData
.Where(r => r.Id == item.CourseDataId &&
r.OpenNow ||
r.Title.Contains(text) ||
r.Deck.Contains(text) ||
r.CourseCategori.SearchWord
.Split(new[] {",", ", ", "/"},
StringSplitOptions
.RemoveEmptyEntries) //online undervisning,undervisning,computer undervisning
.Any(x => x.Contains(text))).ToList(); //undervisning
}
}
else
{
list = _dbContext.CourseData.Where(r => r.OpenNow &&
r.Title.Contains(text) ||
r.Deck.Contains(text) ||
r.Text.Contains(text) ||
r.CourseCategori.SearchWord
.Split(new[] {",", ", ", "/"},
StringSplitOptions
.RemoveEmptyEntries) //online undervisning,undervisning,computer undervisning
.Any(x => x.Contains(text))).ToList();
}
return list;
}
Error code here:
The LINQ expression 'DbSet .Join( outer: DbSet, inner: c => EF.Property<Nullable>(c, "CourseCategoriId"), outerKeySelector: c0 => EF.Property<Nullable>(c0, "Id"), innerKeySelector: (o, i) => new TransparentIdentifier<CourseData, CourseCategori>( Outer = o, Inner = i )) .Where(c => c.Outer.OpenNow && c.Outer.Title.Contains(__text_0) || c.Outer.Deck.Contains(__text_0) || c.Outer.Text.Contains(__text_0) || c.Inner.SearchWord.Split( separator: string[] { ",", ", ", "/", }, options: RemoveEmptyEntries) .Any(x => x.Contains(__text_0)))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.