ILoadable.ToDictionary<TKey>(Func<TModel, TKey> keySelector) Method
.NET Standard 2.x
Creates a Dictionary<Tkey, TModel>
object from the result set according to the specified key selector function.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
Dictionary<TKey, TModel> ToDictionary<TKey>(Func<TModel, TKey> keySelector);
Parameters
keySelector
System.Func<TModel, TKey>
A function used to specify the key of the dictionary.
Returns
System.Collections.Generic.Dictionary<TKey, TModel>
Returns a Dictionary<TKey, TModel>
object that includes all of the data of the result set.
Examples
The following code example demonstrates how to get a dictionary of students.
using Appeon.ApiDoc.Models.School;
namespace Appeon.ApiDoc.ILoadableExamples
{
public class ToDictionaryExample
{
private SchoolContext _context;
public ToDictionaryExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
var loadable = _context.SqlModelMapper.Load<Student>();
// Creates a Dictionary<string,student> that includes the data of the
// result set.
var students = loadable.ToDictionary(o => o.PersonID);
}
}
}
Example Refer To
Model Class: Student
Applies to
.NET Standard
2.x