locked
Dynamic Data Attribute Trouble. RRS feed

  • Question

  • User2133584750 posted

    I have a property of an object called Contract. It is called client (the GUID of Client in the contract table links to the client in the Client table).

    I am trying to manipulate its (the client property of the contract entity) order in the dynamic data grid using the new columnorder attribute in the dynamic data futures. I am also trying to manipulate its filter order using the filter attribute.

    Both attributes can be seen here, I am using code as is from these examples: http://quickstarts.asp.net/previews/dynamicdata/dd_NewAttributes.htm

    I am using EF and dynamic data futures.

    I can place the attributes in code, intellisense picks them up, however *no change* happens in the application runtime. (No reordering, like I never placed the attributes, no errors).

     Here is my code from the metadata:

    namespace ContractsManagement

    {

    [
    MetadataType(typeof(ContractsMetaData))]

    partial class Contracts

    {

    public Contracts()

    {

    GUID =
    Guid.NewGuid();

    }

    }

    partial class ContractMetaData

    {

    [Filter(Enabled=true, Order=1)]
    [ColumnOrder(1)]
    public object Client { get; set; }

    }

    }

     Am I missing something?

    Tuesday, February 17, 2009 12:19 PM

Answers

  • User-1005219520 posted

    >> I am using the 7/16 release

    Don't use the 7/16 release, that's ancient history

    >> I havent seen a working solution yet with DD and EF and GUID generation.

    As I said previously, all you need to do is annotate the partial class GUID property with   [ScaffoldColumn(false)]

    [DisplayName("User Tbl ")]
    [MetadataType(typeof(UserTblMD))]
    public partial class UserTbl {
        public class UserTblMD {
            [ScaffoldColumn(false)]
            public object PKguid { get; set; }
        }
    }

     Using the above, I can insert into the entity UserTbl and the DB generates the GUID PK.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 18, 2009 12:28 PM

All replies

  • User-1005219520 posted

    <STRIKE>>>partial class Contracts</STRIKE>

    <STRIKE>You probably need public - copy the partial declaration from the data model.</STRIKE>

    >>GUID = Guid.NewGuid();

    I assume the GUID is a PK or other unique identifier. You ctor will run once for every row read. You only need new Guids on insert - and you should arguably generate them on the server, not the client.

    Use ScaffoldTable(false) or ScaffoldColumn(false) to verify you have the correct (matching) signature on your partial class.

    Tuesday, February 17, 2009 1:07 PM
  • User-797310475 posted

    I can place the attributes in code, intellisense picks them up, however *no change* happens in the application runtime. (No reordering, like I never placed the attributes, no errors).

    Hi JKC,

    What you are missing is the fact that in the Futures sample the page templates configure an instance of AdvancedFieldGenerator on the GridView and DetailsView. That component is what performs the ordering.

    However keep in mind that ColumnOrder and FilterOrder are no longer in the latest bits. You should take a look at the latest Dynamic Data Preview 2. That build contains a new attribute called DisplayAttribute that combines the concepts covered in the 2 earlier attributes.

    Tuesday, February 17, 2009 1:59 PM
  • User2133584750 posted

    Thanks, I'll take a look and play around with this... I'll post back when working.

    Tuesday, February 17, 2009 4:42 PM
  • User2133584750 posted

    Thanks, I took a look and that public didnt solve it, I'll examine the post below and report back.

     In regards to the second point, I agree, however, I have newid() as default being generated in SQL, but like post: http://forums.asp.net/t/1192966.aspx, I continually get the 0000 based guid... I'm not using l2s so I can't define autogeneration... I'm guessing that I just need to set the value of GUID somewhere else and not in the ctor... and obviously i dont want to much up data model code.

    Tuesday, February 17, 2009 4:51 PM
  • User-1005219520 posted

    >>public didnt solve it,

    See Marcin's post.  

    EF uses StoreGeneratedPattern="Computed" in the SSDL - if it's not there add it. All you need is ScaffoldColumn(false) on the GUID and the server will take care of it. 99.9% of the time you don't want to show GUIDs

    Tuesday, February 17, 2009 5:43 PM
  • User2133584750 posted

    Precisely. Thanks. I'll give it a try and post the results.

    Wednesday, February 18, 2009 7:53 AM
  • User2133584750 posted

    I add that in an I recieve an exception:

    Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: An error occurred while updating the entries. See the InnerException for details.

    I take it out and it works (adding in the 000 based guid).

    In the ctor it works, but obviously this is not the best place for the guid generation...

     Thoughts? I added the computed line via intellisence, no typos.

    Wednesday, February 18, 2009 10:40 AM
  • User2133584750 posted

    Following that, combing through the forums, I havent seen a working solution yet with DD and EF and GUID generation. I have seen it with L2S. To clarify, Is EF not capable as of yet (in DDp1), is it me, or is it the initial lack DD Preview 2 and DD Preview 2 solves this issue?

    Rather than continue to ask questions that most definitely are the result of my lack of understanding (and I apologize, but questions that waste your time of which I've already taken much of) is there a working example of  DD and EF with GUID generation somewhere on the net I could examine (that I have yet to find)?

     I'll examine the attribute issue separately, I realize that DDp2 most likely is the requirement and that I likely have DDp1 installed.

     Thank you for your efforts.

    Wednesday, February 18, 2009 10:54 AM
  • User2133584750 posted

    Also, I am using the 7/16 release as mentioned on your blog here, would that not have the additional attributes?:

    http://blogs.msdn.com/marcinon/

     

    Wednesday, February 18, 2009 11:42 AM
  • User-1005219520 posted

    >> I am using the 7/16 release

    Don't use the 7/16 release, that's ancient history

    >> I havent seen a working solution yet with DD and EF and GUID generation.

    As I said previously, all you need to do is annotate the partial class GUID property with   [ScaffoldColumn(false)]

    [DisplayName("User Tbl ")]
    [MetadataType(typeof(UserTblMD))]
    public partial class UserTbl {
        public class UserTblMD {
            [ScaffoldColumn(false)]
            public object PKguid { get; set; }
        }
    }

     Using the above, I can insert into the entity UserTbl and the DB generates the GUID PK.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 18, 2009 12:28 PM
  • User2133584750 posted

    Again, thank you for your time. I'll look into another release. That must be the issue. I already have the scaffoldcolumn(false) in place (have had).

     I'll follow up.

    Wednesday, February 18, 2009 1:17 PM
  • User-1005219520 posted

    Make sure you get rid of GUID = Guid.NewGuid();

    Wednesday, February 18, 2009 1:22 PM
  • User2133584750 posted

    No worries, commented out. Thanks.

    Wednesday, February 18, 2009 2:07 PM
  • User2133584750 posted

    So, I loaded the Sample from the DDp2. I ripped out everything and recreated my project using the appropriate dll and templates and added in my model. The display attribute rocks, thanks guys. Makes much more sense than the indiviudal atts that were there.

    I cant say however that the below works. I've added that into the ssdl, commented out my guid generation that I had in my ctor and have scaffolding set to false for the guid column and have newid() as the default value for the column in sql, however, I get a javascript error when I hit submit. I take the below out and uncomment my guid generation from my ctor and everything is kosher...

    StoreGeneratedPattern="Computed"

    Thursday, February 19, 2009 8:40 AM