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
|
Getting this compile time error:
using (var uow = _context.CreateUnitOfWork()) { Registry r = new Registry();
Console.WriteLine("ID: " + r.Id);
User u = new User(); Console.WriteLine("Total Users: "+ uow.Users.Count()); } ERROR: Property or indexer 'Mindscape.LightSpeed.Entity<long>.Id' cannot be assigned to -- it is read only
QUESTION how can I change it, so I can set ID programmatically?
that's the ER diagram http://screencast.com/t/YWU5ZTkzY
we have tried many times implement the inheritance but found many disadvantages, so now we want ORM to handle just atomic tables and having service class do everything else (nice joins, setting up IDs on child tables etc). But right now it seems I can't set the ID of the parent table Please advise |
|
|
Tried to do a PK solution instead of PF, here is a new ER Diagram: http://screencast.com/t/ZWZiN2FlYmQ now User, Project, Task, Note has its own PK fields and ID field of each table is FK to Registry.ID That !should! give me the way to fill ID fields programmatically, but it doesn't!!!! http://screencast.com/t/NzRhOTVkNTgt here is the code:
Registry r = new Registry(); r.Created = DateTime.Now; uow.Add(r); uow.SaveChanges();
Console.WriteLine("ID: " + r.Id);
u.Id = 2; u.FirstName = "Dmitry"; u.LastName = "Semenov"; u.Email = "dmitry@test.com"; u.Password = "test"; uow.Add(u); uow.SaveChanges();
and here is what I get:
Unhandled Exception: MySql.Data.MySqlClient.MySqlException: Field 'ID' doesn't have a default value at MySql.Data.MySqlClient.MySqlStream.OpenPacket() at MySql.Data.MySqlClient.NativeDriver.ReadResult(UInt64& affectedRows, Int64& lastInsertId) at MySql.Data.MySqlClient.MySqlDataReader.GetResultSet() at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior ) at MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar() at ◄.☻.☻.⌂() at ◄.☻.⌂(IUnitOfWork , IDbCommand , ☺ ) at ◄.☻.⌂(IUnitOfWork , IDbCommand ) at ♫.☼.⌂(Entity , ☺ ) at ♫.☼.⌂(Entity , ICollection`1 ) at ♫.☼.⌂(Entity , List`1 ) at ♫.☼.⌂(UnitOfWorkBase , IEnumerable`1 , IEnumerable`1 ) at Mindscape.LightSpeed.UnitOfWork.SaveChanges(Boolean reset) at Mindscape.LightSpeed.UnitOfWorkBase.SaveChanges() at Sandbox.Program.Main(String[] args) in D:\Development\net\experiments\DAL_ MVC_EXTJS\Sandbox\Program.cs:line 42
any ideas?
Maybe you !CAN'T! CALL any field "ID" ? |
|
|
Yes Indeed, if I changed the name of the column in the model (not in DB) to be registryID instead of ID it worked. How can I get the column to have "ID" name or that's not possible. |
|
|
The entity identifier (primary key) in the model is ALWAYS the Entity<T>.Id property. If you create a new property in the model named, say, RegistryId, then what you get is a new data property: this will NOT be the identifier. To assign your own identifier value, you must override Entity.GeneratedId(). See: http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=1916 for more info about how to do this and why we do it this way rather than making Id settable. |
|