EF Core: use a dictionary property - c#

Is there a way to fill a dictionary property with Entity Framework Core?
For performance reasons, we like to search in the application instead of the database. As a list won’t scale well, we like to use a dictionary.
For example (simplified example)
class Course
{
public Dictionary<string, Person> Persons { get; set; }
public int Id { get; set; }
}
class Person
{
public string Firstname { get; set; }
public string Lastname { get; set; }
}
Things I tried
Naively just add a dictionary property. This will result the in following error:
System.InvalidOperationException: The property 'Persons' could not be mapped, because it is of type 'Dictionary' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
Try adding a value conversion (with HasConversion), but conversion one only works on a single item and not on collections. The HasMany already gives a compile error:
builder
.HasMany<Person>(c => c.Persons) //won't compile, Persons isn't a IEnumerable<Person>
.WithOne().HasForeignKey("PersonId");
Creating a custom collection class (inherited from Collection<T> and implement InsertItem, SetItem etc.) – unfortunately this also won’t work because EF Core will add the item to the collection and first after that will fill the properties (at least with our OwnsOne properties, that is not in the demo case) - SetItem won't be called afterwards.
Adding a "computed" property that will build the dictionary, the setter won't be called (the list is updated every time with partly values, a bit the same as above). See try:
class Course
{
private Dictionary<string, Person> _personsDict;
public List<Person> Persons
{
get => _personsDict.Values.ToList();
set => _personsDict = value.ToDictionary(p => p.Firstname, p => p); //never called
}
public int Id { get; set; }
}
Of course I could build a dictionary in the Repository (using the Repository pattern), but that’s tricky as I could forget some parts – and I really prefer compile time errors over run-time errors and declarative style over imperative style code.
Update, to be clear
this isn't a code first approach
the idea to change the mapping in EF Core, so no database changes. - I haven't tagged the database on purpose ;)
If I use a List instead of Dictionary, the mapping works
It's a 1:n or n:m relationship in the database (see HasMany - WithOne)

I don't think saving a dictionary is a good idea (I can't even image how it would be done in the database). As I can see from you source code you are using the FirstName as key. In my opinion you should change the dictionary to a HashSet. This way you can keep the speed but also save it to the database.
Here is an example:
class Course
{
public Course() {
this.People = new HashSet<Person>();
}
public ISet<Person> People { get; set; }
public int Id { get; set; }
}
After this you can create a dictionary from it, or keep using the hashset. Sample for dictionary:
private Dictionary<string, Person> peopleDictionary = null;
public Dictionary<string, Person> PeopleDictionary {
get {
if (this.peopleDictionary == null) {
this.peopleDictionary = this.People.ToDictionary(_ => _.FirstName, _ => _);
}
return this.peopleDictionary;
}
}
Please note that this would mean that your People Set becomes unsynced after you add/remove to/from the dictionary. In order to have the changes in sync you should overwrite the SaveChanges method in your context, like this:
public override int SaveChanges() {
this.SyncPeople();
return base.SaveChanges();
}
public override int SaveChanges(bool acceptAllChangesOnSuccess) {
this.SyncPeople();
return base.SaveChanges(acceptAllChangesOnSuccess);
}
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default) {
this.SyncPeople();
return base.SaveChangesAsync(cancellationToken);
}
public override Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default) {
this.SyncPeople();
return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
}
private void SyncPeople() {
foreach(var entry in this.ChangeTracker.Entries().Where(_ = >_.State == EntityState.Added || _.State == EntityState.Modified)) {
if (entry.Entity is Course course) {
course.People = course.PeopleDictionary.Values.ToHashSet();
}
}
}
EDIT: In order to have a running code, you will need to tell the EF not to map the dictionary, via the NotMapped Attribute.
[NotMapped]
public Dictionary<string, Person> PeopleDictionary { ... }

Seems someone has been struggling with that and found solution. See: Store a Dictionary as a JSON string using EF Core 2.1
The definition of the entity is as follows:
public class PublishSource
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public Dictionary<string, string> Properties { get; set; } = new Dictionary<string, string>();
}
In the OnModelCreating method of the database context I just call HasConversion, which does the serialization and deserialization of the dictionary:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<PublishSource>()
.Property(b => b.Properties)
.HasConversion(
v => JsonConvert.SerializeObject(v),
v => JsonConvert.DeserializeObject<Dictionary<string, string>>(v));
}
One important thing I have noticed, however, is that when updating the entity and changing items in the dictionary, the EF change tracking does not pick up on the fact that the dictionary was updated, so you will need to explicitly call the Update method on the DbSet<> to set the entity to modified in the change tracker.

You could add a new property PersonsJson for storing the JSON data. It automatically serializes or deserializes the JSON data into the Persons property when data is retrieved from DB or stored to DB. Persons property is not mapped, only PersonsJson is mapped.
class Course
{
[NotMapped]
public Dictionary<string, Person> Persons { get; set; }
public string PersonsJson
{
get => JsonConvert.SerializeObject(Persons);
set => Persons = JsonConvert.DeserializeObject<Dictionary<string, Person>>(value);
}
public int Id { get; set; }
}

Create a partial class of the type generated by EF.
Create a wrapper class that holds a dictionary or implement IDictionary.
Implement the Add function so it also adds the value to the list that EF uses.
The first time a method that operates on the Persons list or dictionary is called make sure they are properly initialized
You would end up with something like:
private class PersonsDictionary
{
private delegate Person PersonAddedDelegate;
private event PersonAddedDelegate PersonAddedEvent; // there can be other events needed too, eg PersonDictionarySetEvent
private Dictionary<string, Person> dict = ...
...
public void Add(string key, Person value)
{
if(dict.ContainsKey(key))
{
// .. do custom logic, if updating/replacing make sure to either update the fields or remove/re-add the item so the one in the list has the current values
} else {
dict.Add(key, value);
PersonAddedEvent?.(value); // your partial class that holds this object can hook into this event to add it its list
}
}
// ... add other methods and logic
}
public partial class Person
{
[NotMapped]
private Dictionary<string, Person> _personsDict
[NotMapped]
public PersonsDictionary<string, Person> PersonsDict
{
get
{
if(_personsDict == null) _personsDict = Persons.ToDictionary(x => x.FirstName, x => x); // or call method that takes list of Persons
return _personsDict;
}
set
{
// delete all from Persons
// add all to Persons from dictionary
}
}
}
public List<Person> Persons; // possibly auto-generated by entity framework and located in another .cs file
if your going to access the list of Persons directly then you need to also modify your partial class so that adding to the list will add to the dictionary (perhaps using a wrapper for the Persons list or a wrapper class all together)
there are some improvements to be made if dealing with large data sets or needing optimization, eg not deleting/re-adding all elements when setting new dictionary
you might need to implement other events and custom logic depending on your requirements

i don't know if this would solve the problem or not, but when i tried to run your provided code. it triggered a runtime error that required me to modify the Persons property declaration to like like this
public Dictionary<string, Person> Persons { get; set; } = new Dictionary<string, Person>();
this eliminated the runtime error and every thing went fine.

Related

EF Core, include derived type property

I have a small problem with a specific include statement.
My datastructure is as follows:
[Table("item")]
public class Item
{
public int Id { get; set; }
public string ItemCode { get; set; }
...
}
public abstract class DerivedItemAbstractBase : Item
{
[ForeignKey("ItemId")]
public List<Assignment> Assignments { get; set; }
...
}
[Table("item")]
public class DerivedItemA : DerivedItemAbstractBase
{
...
}
[Table("item")]
public class DerivedItemB : DerivedItemAbstractBase
{
...
}
public class ItemContext : DbContext
{
public DbSet<Item> Items { get; set; }
...
}
Now I want to get a list of all DerivedItemA and include properties of it.
I have the following method:
public List<DerivedItemA> GetDerivedItemsA()
{
var list = _context.Items
.Include(x => (x as DerivedItemA).Assignments)
.ToList();
}
This code compiles just fine and is something I have found on stackoverflow.
However executing this results in an exception with the short message Invalid include.
I dont know how to solve this problem.
The project is a database-first approach so I have no control over the database.
All items are stored in the same table item.
I cannot create multiple DbSets because there is no discriminator column in the table and I
cannot configure a custom discriminator in code because it would need to discriminate based on multiple properties and not a single property.
Is there any other way of doing this?
Currently I am solving it by iterating through all ItemContext.Items then doing a .Select() on each and creating a new DerivedItemA. After that I manually set every Assignment by iterating from the Assignment table.
However this approach takes far too long and it would be a lot quicker if I could just include it in the initial query.

Get field by name in Entity Framework

What would be the easiest and least labour intensive (from the software POV) for me to be able to get a property (to be read and modified) from an entity generated via the Entity Framework?
Example (and simplified code) below:
// <auto-generated> from Entity Framework
public partial class tblCustomer
{
public int CustomerID { get; set; }
public string Status { get; set; }
}
For instance I would like:
tblCustomer customer = new tblCustomer();
int pCustomerID = customer.GetFieldByName("CustomerID");
pCustomerID = 100;
I've read a lot of answers about Reflection, but also comments that it's heavy processing (may be a bit excessive for my needs).
My example code may seem rather simplistic (so a solution would be rather pointless for that, the real code is based on large tables), but if there was some sort of GetFieldByName function I could reduce my code significantly as I have a lot of repetitious code doing the same stuff (just to different columns).
If I understand your problem correctly, I think you can use the changetracker for this (if the entity is in the context already).
dbContext.Entry(customer).CurrentValues["CustomerID"]
will give you the value of CustomerID for the customer object, provided it is attached to the dbContext instance.
If it is not part of the context, you can use Attach() to attach it first, or use Add(), if it's supposed to be a new record.
If you don't like to use Reflection the only way that i know is using a dictionary in your entities and also you can put all these stuff in a base class and your entities inherit it for example like that:
[Serializable]
public class BaseEntity
{
Dictionary<string, object> _dic;
public BaseEntity()
{
_dic = new Dictionary<string, object>();
}
public object this[string propertyName]
{
get
{
return _dic[propertyName];
}
set
{
_dic[propertyName] = value;
}
}
}
public class tblCustomer : BaseEntity
{
public int CustomerID
{
get
{
return (int)this["CustomerID"];
}
set
{
this["CustomerID"] = value;
}
}
public string Status
{
get
{
return (string)this["Status"];
}
set
{
this["Status"] = value;
}
}
}
tblCustomer customer = new tblCustomer();
int pCustomerID = customer["CustomerID"];
and about performance cost of Reflection you can for first time store your memberInfos in a static field and use it for all instances.

Update Entity property in EF where property is another entity

I am using Entity Framework 6 and I need to update the properties of a entity.
I have the following entities:
public class File
{
public Int32 Id { get; set; }
public Byte Data { get; set; }
public DateTime Updated { get; set; }
public virtual Mime Mime { get; set; }
}
public class Mime
{
public Int32 Id { get; set; }
public String Name { get; set; }
public virtual ICollection<File> Files { get; set; }
}
Then I used the following:
_repository.Update<File>(file, x => x.Data, x => x.Mime, x => x.Updated);
The repository method is the following:
public void Update<T>(T entity,
params Expression<Func<T, Object>>[] properties)
where T : class
{
_context.Set<T>().Attach(entity);
foreach (var property in properties)
{
MemberExpression expression =
property.Body is MemberExpression ?
(MemberExpression)property.Body :
(MemberExpression)(((UnaryExpression)property.Body)
.Operand);
_context.Entry<T>(entity)
.Property(expression.Member.Name).IsModified = true;
}
}
This works fine for Data and Updated properties but not for Mime. I get the error:
The property 'Mime' on type 'File' is not a primitive or complex property. The Property method can only be used with primitive or complex properties. Use the Reference or Collection method.
Is it possible to make this work and integrate it on my repository method?
Yes, I think that can be done. The problem here is that I didn't see any easy way to check whenever a property is part of the table, or is it navigational property. Thus it's hard to call the right behavior.
If you're interested, take a look at EF6 source code, InternalEntityEntry.cs -> Property(..) which does huge amount of property validation through metadata.
The main idea is to basically scan your conceptual model, and determine whenever the property is navigational property(eg if the property leads to another table), or if it's complex/primitive.
According to that, you call the right functionality.
var propertyName = expression.Member.Name;
var propertyType = __get_property_type__(propertyName);
if(propertyType==Property || propertyType==Complex)
{
_context.Entry<T>(entity)
.Property(propertyName).IsModified = true;
continue;
}
if(propertyType==Navigational){
// hm, do we need Attach it first?!
// not sure.. have to test first.
dynamic underlyingReference = entity.GetType()
.GetProperty(propertyName)
.GetValue(entity, null);
_context.Entry(underlyingReference).State = EntityState.Modified;
}
The catch here is to have __get_property_type__ that works. There's Microsoft.Data.Edm.dll that let's you work with the conceptual model, but it's not that easy I think.
This is the way how EF6 detects if we're dealing with reference property or not:
EdmMember member;
EdmEntityType.Members.TryGetValue(propertyName, false, out member);
var asNavProperty = member as NavigationProperty;
// if asNavProperty!=null, we have navigation property.
100% Gerts point. I see no reason to approach the problem they way you have.
Anyway, to answer the question. You have another answer there. Potentially useful.
Whats missing is this:
How to get a list of managed types from the context.
public static IList<Type> GetContextManagedTypes(DbContext context) {
ObjectContext objContext = ((IObjectContextAdapter)context).ObjectContext;
MetadataWorkspace workspace = objContext.MetadataWorkspace;
IEnumerable<EntityType> managedTypes = workspace.GetItems<EntityType>(DataSpace.OSpace);
var typeList = new List<Type>();
foreach (var managedType in managedTypes) {
var pocoType = managedType.FullName.GetCoreType();
typeList.Add(pocoType);
}
return typeList;
}

Map a Dictionary in Entity Framework Code First Approach

I have a dictionary like this:
/// <summary>
/// Gets the leave entitlement details.
/// </summary>
/// <value>The leave entitlement details.</value>
public Dictionary<string, EmployeeLeaveEntitlement> LeaveEntitlementDetails { get; set; }
And I want to map it to the database. Is it possible to use a protected or private List<> for that? such as:
/// <summary>
/// Gets the leave entitlement details.
/// </summary>
/// <value>The leave entitlement details.</value>
public Dictionary<string, EmployeeLeaveEntitlement> LeaveEntitlementDetails { get; set; }
public List<EmployeeLeaveEntitlement> LeveEntitlementStore
{
get
{
List<EmployeeLeaveEntitlement> leaveEntitlements = new List<EmployeeLeaveEntitlement>();
foreach (KeyValuePair<string, EmployeeLeaveEntitlement> leaveType in LeaveEntitlementDetails)
{
leaveEntitlements.Add(leaveType.Value);
}
return leaveEntitlements;
}
set
{
foreach (EmployeeLeaveEntitlement item in value)
{
this.LeaveEntitlementDetails.Add(item.LeaveType, item);
}
}
}
Can anyone help me?
Entity Framework does not presently support mapping a Dictionary natively.
See the following for more information and work-arounds:
Entity Framework 4 POCO with Dictionary
EF Code First - Map Dictionary or custom type as an nvarchar
http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/a51ba903-2b8b-448e-8677-d140a0b43e89/
EF Core 2.1 introduced a new feature called value conversion:
Value converters allow property values to be converted when reading from or writing to the database.
This feature highly simplifies the serialization approach mentioned in previous answers, which means, the introduction of on an additional "helper" property and the marking of your dictionary property as [NotMapped] becomes unnecessary.
Here are some lines of code tailored to your case (note, I am using Json.NET, but feel free to use your serializer of choice):
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace My.Name.Space
{
public class MyEntity
{
public int Id { get; set; }
public Dictionary<string, EmployeeLeaveEntitlement> LeaveEntitlementDetails { get; set; }
}
public class MyEntityConfiguration : IEntityTypeConfiguration<MyEntity>
{
public void Configure(EntityTypeBuilder<MyEntity> builder)
{
builder.ToTable("MyEntity");
builder.HasKey(e => e.Id);
builder
.Property(e => e.LeaveEntitlementDetails)
.IsRequired()
.HasConversion(
v => JsonConvert.SerializeObject(v),
v => v == null
? new Dictionary<string, EmployeeLeaveEntitlement>() // fallback
: JsonConvert.DeserializeObject<Dictionary<string, EmployeeLeaveEntitlement>>(v)
);
}
}
}
Using a XML Column in DB
So today I came across the same problem, and after thinking about it I found a cool solution which I would like to share with the community even if I am late.
Basically I've made a wrapping system which saves the data in the Dictionary to the Database as XML Column, so later I can also query the XML from the DB if I want.
Pro of this approach
Easy to use
Fast implementation
You can use the dictionary
You can query the XML column
First of all here's the bone of all my models:
public abstract class BaseEntity
{
/// <summary>
/// ID of the model
/// </summary>
public int ID { get; set; }
}
Suppose I have a model which contain a Dictionary<string,string> and a String property which contains the logic to Serialize and Deserialize the dictionary in XML, like the following snippet:
public class MyCoolModel : Base.BaseEntity
{
/// <summary>
/// Contains XML data of the attributes
/// </summary>
public string AttributesData
{
get
{
var xElem = new XElement(
"items",
Attributes.Select(x => new XElement("item", new XAttribute("key", x.Key), new XAttribute("value", x.Value)))
);
return xElem.ToString();
}
set
{
var xElem = XElement.Parse(value);
var dict = xElem.Descendants("item")
.ToDictionary(
x => (string)x.Attribute("key"),
x => (string)x.Attribute("value"));
Attributes = dict;
}
}
//Some other stuff
/// <summary>
/// Some cool description
/// </summary>
[NotMapped]
public Dictionary<string, string> Attributes { get; set; }
}
Then I've implemented a BaseMapping class which ineherits from EntityTypeConfiguration<T>
class BaseMapping<TEntity> : EntityTypeConfiguration<TEntity>
where TEntity : Model.Base.BaseEntity
{
public BaseMapping()
{
//Some basic mapping logic which I want to implement to all my models
}
}
And after a Custom Mapping for MyCoolModel
class MyCoolModelMapping
: BaseMapping<Model.MyCoolModel>
{
public MyCoolModelMapping()
{
Property(r => r.AttributesData).HasColumnType("xml");
}
}
Now notice that when AttributesData value is requested by EntityFramework it just serialize the dictionary and the same happens when I retrive data from the DB and EntityFramework sets the data to the field, which then
deserializes the object and sets it to the dict.
And finally I have override the OnModelCreating of my DbContext
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.Add(new Mappings.BaseMapping<SomeOtherModel>());
modelBuilder.Configurations.Add(new Mappings.MyCoolModelMapping());
//Other logic
}
And that's it! Now I can use the dictionary from my business logic and this "wrapping" handles all the stuff need to save the data to the DB and retrive the data from it.
I had a similar problem with EF were I wanted to convert a query returned list, into a class property's dictionary equivalent. Very similar to how you want to have LeaveEntitlementDetails wrapped by LeveEntitlementStore
For example:
class A
{
[NotMapped()]
public Dictionary<int, DataType> Data {get; set}
//refers to Data.Values
public ICollection<DataType> DataAsList {get; set}
}
Where I wanted DataAsList to essentially wrap Data.Values
After a lot of trial and error, I discovered that EF, for collections (maybe more) alters through the getter's returned value (rather than the setter).
I.e. when initializing from my db:
var pollquery=From bb In DBM.Dbi.DataTable.Includes("DataAsList")
Where bb.Id = id
Select bb;
ClassA objInstance = pollquery.First();
ClassA.DataAsList's setter was never being called, but the getter was during EF's internal construction of my object.... Conclusion: EF is using a reference retrieved from the getter of property ClassA.DataAsList, and adding objects to it.
So I wrapped my getter's return value for DataAsList in an ObservableCollection and added a handler for CollectionChanged args and sure enough, my handler for CollectionChanged was picking up .Add calls.
So heres my hackaround-workaround:
class A : INotifyPropertyChanged
{
//So we can let EF know a complex property has changed
public event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged;
//here's our actual data, rather than an auto property, we use an explicit member definition so we can call PropertyChanged when Data is changed
private Dictionary<int, DataType> m_data = new Dictionary<int, DataType>();
//not mapped property as it's not mapped to a column in EF DB
[NotMapped()]
public Dictionary<int, DataType> Data {
get { return m_data; }
set {
m_data = value;
//now call PropertyChanged for our Front (so EF will know it's been changed)
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs("DataAsList"));
}
}
}
//this is our front for the data, that we use in EF to map data to
[DebuggerHidden()]
public ICollection<DataType> DataAsList {
get {
ObservableCollection<DataType> ob = new ObservableCollection<DataType>(Data.Values());
ob.CollectionChanged += Handles_entryListChanged;
return ob;
}
set {
//clear any existing data, as EF is trying to set the collections value
Data.Clear();
//this is how, in my circumstance, i converted my object into the dictionary from an internal obj.Id property'
foreach (DataType entry in value) {
entryions.Add(entry.id, entry);
}
}
}
//This will now catch wind of any changes EF tries to make to our DataAsList property
public void Handles_entryListChanged(object sender, NotifyCollectionChangedEventArgs e)
{
//Debugger.Break()
switch (e.Action) {
case NotifyCollectionChangedAction.Add:
foreach (DataType entry in e.NewItems) {
m_data.Add(entry.Id, entry);
}
break;
default:
Debugger.Break();
break;
}
}
}
Note the Magic is the:
public ICollection<DataType> DataAsList {
get {
ObservableCollection<DataType> ob = new ObservableCollection<DataType>(Data.Values());
ob.CollectionChanged += Handles_entryListChanged;
return ob;
}
where we subscribe to any changes made to the returned list and Handles_entryListChanged where we handle and essentially replicate any changes made.
As mentioned in here, One important thing after object serialization, is that when updating the entity and changing items in the dictionary, the EF change tracking does not pick up on the fact that the dictionary was updated, so you will need to explicitly call the Update method on the DbSet<> to set the entity to modify in the change tracker.
there is also another good sample here

Is it possible to have a List<string> as a property on an active record class

Is it possible to have a HasMany relationship of a basic type such as String, on an ActiveRecord class, without the need for creating another entity such as (TodoListItem) to hold the value.
[ActiveRecord]
public class TodoList
{
[PrimaryKey]
public int Id
{
get { return _id; }
set { _id = value; }
}
[HasMany(typeof(string)]
public IList<string> Items
{
get { return _items; }
set { _items= value; }
}
}
Can anyone help?
Yes, you can do this. You can map a one-to-many relation to a built-in or simple type (value type or string) rather than a persisted type.
You'll need to specify the ColumnKey, Table and Element params in the HasMany attribute declaration to get it to wire up properly. You have to have a surrogate key column so the AR can handle updates and cascades, and then Element tells AR which column in the table holds the simple value it will use to make the list.
[HasMany(typeof(string), Table="ToDoList_Items",
ColumnKey = "ListItemID", Element = "Item")]
public IList<string> Items { get; set; }
(or something similar - I haven't got a compiler handy on this box to check it; but per the API docs it ought to work.)
Speaking of which, if you haven't already had a look, http://api.castleproject.org is kinda indispensible for any work with the Castle stack.
In ActiveRecord, your types map to a record in a table (by default). It seems like you are confusing how this type should map to your table.
The MyClass type should have a definition something like this (excluding the PK settings):
[ActiveRecord(Table = "MyTable")]
public class MyClass : ActiveRecordBase<MyClass>
{
[Property]
public int Id { get; set; }
[Property]
public int MyClassId { get; set; }
[Property]
public string ListItem { get; set; }
}
Then, to load the list:
public void LoadMyClasses()
{
MyClass[] results = MyClass.FindAll();
}
I'd suggest you spend some time with the ActiveRecord documentation (or tutorial) as that should also help clear up any confusion.

Categories