This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
CODE:
------------------------
var product = new Product(); ------------------------
Error:
System.NotImplementedException was unhandled
------------------------------
However, if I extend the entity class by overriding the GeneratedId(), I can get it to work: public
partial class Product {
public Product()
{ } public Product(Guid id)
{ this.internalId = id;
} [ Transient]
private Guid? internalId;
public void SetId(Guid id)
{ this.internalId = id;
} protected override object GeneratedId()
{ if (this.internalId.HasValue)
{ return this.internalId;
} else {
return base.GeneratedId();
} } }
|
|
|
Is this running against the SimpleDB provider? And if so, could you provide some details on how your context is configured (either config block or code depending on your usage).
Thanks! |
|
|
Yes, we are using the SimpleDB provider. I have created a simple console app project to work through 3.0 issues. It consists of 2 classes and a simple lightspeed model with one Product entity: Program.cs
----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Text; using Mindscape.LightSpeed; using Mindscape.LightSpeed.Logging; using System.Configuration;
namespace LightSpeed3Tests { class Program { static void Main(string[] args) { var data = context.CreateUnitOfWork();
var p1 = data.Products.Where(p => p.CreatedOn < DateTime.UtcNow).OrderBy(p => p.Name).ToList();
Console.WriteLine(p1.Count + " products");
for (int i = 1; i <= 2; i++) { data.Add(new Product(Guid.NewGuid()) { Name = "test " + i.ToString(), Description = "this is a test " + i.ToString(), Price = 1.45F + i, IsActive = true });
}
Console.WriteLine("added 2 products setting Guid Explicitly");
data.SaveChanges();
data.Add(new Product() { Name = "test", Description = "test", Price = 1.32F, IsActive = true }); data.SaveChanges();
Console.WriteLine("added 1 product with lightpeed generated Guid");
Console.ReadLine(); }
public static readonly LightSpeedContext<LightSpeedModel1UnitOfWork> context = new LightSpeedContext<LightSpeedModel1UnitOfWork> { AutoTimestampMode = Mindscape.LightSpeed.AutoTimestampMode.Utc, CascadeDeletes = false, ConnectionString = String.Format("Access Key={0};Secret Access Key={1}", ConfigurationManager.AppSettings["AwsAccessKey"], ConfigurationManager.AppSettings["AwsSecretkey"]), DataProvider = Mindscape.LightSpeed.DataProvider.AmazonSimpleDB, PluralizeTableNames = false, Logger = new TraceLogger() }; } }
Product.cs -----------------------------------------------------------------------------
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Mindscape.LightSpeed;
namespace LightSpeed3Tests { public partial class Product { public Product() { }
public Product(Guid id) { this.internalId = id; }
[Transient] private Guid? internalId;
public void SetId(Guid id) { this.internalId = id; }
protected override object GeneratedId() { if (this.internalId.HasValue) { return this.internalId; } else { return base.GeneratedId(); // ERROR HERE } } } }
and here is the LightSpeed generated model: -------------------------------------------------
using System;
using Mindscape.LightSpeed;
using Mindscape.LightSpeed.Validation;
using Mindscape.LightSpeed.Linq;
namespace LightSpeed3Tests
{
[Serializable]
[System.CodeDom.Compiler.GeneratedCode("LightSpeedModelGenerator", "1.0.0.0")]
[System.ComponentModel.DataObject]
public partial class Product : Entity<System.Guid>
{
#region Fields
private string _name;
private string _description;
private float _price;
private bool _isActive;
#pragma warning disable 649 // "Field is never assigned to" - LightSpeed assigns these fields internally
private readonly System.DateTime _createdOn;
private readonly System.DateTime _updatedOn;
private readonly System.Nullable<System.DateTime> _deletedOn;
#pragma warning restore 649
#endregion
#region Field attribute and view names
/// <summary>Identifies the Name entity attribute.</summary>
public const string NameField = "Name";
/// <summary>Identifies the Description entity attribute.</summary>
public const string DescriptionField = "Description";
/// <summary>Identifies the Price entity attribute.</summary>
public const string PriceField = "Price";
/// <summary>Identifies the IsActive entity attribute.</summary>
public const string IsActiveField = "IsActive";
#endregion
#region Properties
public string Name
{
get { return Get(ref _name, "Name"); }
set { Set(ref _name, value, "Name"); }
}
public string Description
{
get { return Get(ref _description, "Description"); }
set { Set(ref _description, value, "Description"); }
}
public float Price
{
get { return Get(ref _price, "Price"); }
set { Set(ref _price, value, "Price"); }
}
public bool IsActive
{
get { return Get(ref _isActive, "IsActive"); }
set { Set(ref _isActive, value, "IsActive"); }
}
/// <summary>Gets the time the entity was created</summary>
public System.DateTime CreatedOn
{
get { return _createdOn; }
}
/// <summary>Gets the time the entity was last updated</summary>
public System.DateTime UpdatedOn
{
get { return _updatedOn; }
}
/// <summary>Gets the time the entity was soft-deleted</summary>
public System.Nullable<System.DateTime> DeletedOn
{
get { return _deletedOn; }
}
#endregion
}
/// <summary>
/// Provides a strong-typed unit of work for working with the LightSpeedModel1 model.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("LightSpeedModelGenerator", "1.0.0.0")]
public partial class LightSpeedModel1UnitOfWork : Mindscape.LightSpeed.UnitOfWork
{
/// <summary>
/// Initializes a new instance of the LightSpeedModel1UnitOfWork class.
/// </summary>
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public LightSpeedModel1UnitOfWork()
{
}
public System.Linq.IQueryable<Product> Products
{
get { return this.Query<Product>(); }
}
}
}
|
|
|
In your LightSpeedContext declaration, set: IdentityMethod = IdentityMethod.Guid If you don't specify IdentityMethod, LightSpeed tries to use a KeyTable, which fails on SimpleDB because it requires an ADO.NET database connection. |
|
|
Just the info I needed... Thanks! -Joe
|
|