Steve Strong

Hi,

Is it possible to have a default on a column of Guid.NewId() As you can probably guess, I'm using Guids as my primary key, and would like them to be initialised as soon as the object is created. If this isn't possible in the model, is there any way of implementing such logic in a partial class I've had a look, but it doesn't look like there are any suitable methods that I can override to perform logic during construction.

Cheers,

Steve



Re: ADO.NET (Pre-release) Computed Default value for property

Steve Strong

Of course, I meant Guid.NewGuid() :)



Re: ADO.NET (Pre-release) Computed Default value for property

Daniel Simmons - MSFT

Do I have a deal for you... Check out this blog post from a while back that basically addresses exactly this scenario: http://blogs.msdn.com/dsimmons/archive/2006/08/27/727171.aspx

In future CTPs it's our intention to actually make things much simpler on this front, and I'll be writing a blog post detailing how that will work "real soon now" (tm), but the newer, simpler method won't be available until sometime after the Feb CTP in any case, so the above blog post is the right way to do things for now.

- Danny






Re: ADO.NET (Pre-release) Computed Default value for property

Steve Strong

Excellent, that's just what I was looking for! Any hints on the changes that are due in this area in the future would be much appreciated, since it may save me (and others) from starting to implement a way of automatically generating code of this nature. On that topic, is there a way of hooking into the code generation process to augment / modify the output I've taken a look at the EntityClassGenerator class, but can't see how I might extend it.

Cheers,

Steve





Re: ADO.NET (Pre-release) Computed Default value for property

Daniel Simmons - MSFT

The follow-up post on how to make server generated key values work in future CTPs is now up at: http://blogs.msdn.com/dsimmons/archive/2007/02/02/fire-and-forget-key-values-made-easy.aspx

Unfortunately, no, we don't have any mechanism to automatically extend codegen at this time, and I don't think there are any plans for this in Orcas. Certainly this is something that could be interesting in the future, but at the moment the plan is two-fold: 1) Have folks add things to code-gen'd classes just by supplying partial classes (doesn't solve everything but addresses many scenarios). 2) For those folks who really need more control, we will allow the creation of classes that don't inherit from Entity or use our codegen at all by documenting some key interfaces that can be implemented directly on whatever class hierarchy you like in order to enable it to work with the entity framework.

Part #2 won't be in the February CTP, but work is underway now with the view toward bringing it into a future CTP/release.

- Danny






Re: ADO.NET (Pre-release) Computed Default value for property

Steve Strong

Cool, looking forward to the next CTP to see the new key values in action.

As far as more customisable code generation goes, what is the scope for having access to the CodeDom that the EntityClassGenerator is using Partial classes are fine, but in a scenario where I've got a couple of hundred entities, writing these by hand would be somewhat tiresome :) I guess that your answer will be that you want to keep the details of the generated code "undocumented" to allow you to change it internally in the future without breaking existing apps; if that's the case, is there any scope for getting some alternative model exposed that could drive custom code generation, or is the recommended approach to just parse the .csdl file and perform generation from there

Cheers,

Steve





Re: ADO.NET (Pre-release) Computed Default value for property

Daniel Simmons - MSFT

At this point the plan of record is really that you would need to parse the .csdl and do your own codegen, but we'll certainly take the feedback and give it some more thought.

Thanks,
Danny






Re: ADO.NET (Pre-release) Computed Default value for property

unbornchikken

Hi!

March Orcas CTP is not working with StoreGeneratedPattern="identity" i've seen. It throws SqlClient exception with integer to uniqueidentifier conversion problem message. Ok. It is not supported (yet) I think.

But if you want to create sequential Guids for cluster friendly IDs in C#, here is a solution:

http://codebetter.com/blogs/scott.bellware/archive/2006/12/27/156671.aspx

Thanks Scott and Kendall (see below in comments)!

(sorry about my English, i'm just a hungarian coder)





Re: ADO.NET (Pre-release) Computed Default value for property

Daniel Simmons - MSFT

I'm a bit confused about this comment. Can you share a snippet of your ssdl and csdl schema which includes the properties in question It sounds like you have an integer in the DB and a guid in the CLR class or something. Is that right If so, we don't expect this to work in future either... Why wouldn't you just use an integer in both places

- Danny