AnantLabs / codesmith

Automatically exported from code.google.com/p/codesmith
1 stars 0 forks source link

The Fetch Method needs to support Xml database columns. #180

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The Fetch Method needs to support Xml database columns.

The fetch method might not work when UseMemeberVariables set to false. It
doesn't work when UseMemeberVariables is set to true.

The Dataportal_Create more than likely needs to be updated to instantiate
the object.

Original issue reported on code.google.com by bniemyjski on 22 Oct 2009 at 9:15

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 8 Jul 2010 at 11:30

GoogleCodeExporter commented 9 years ago
Yeah, this would be great.

Original comment by bill.n...@gmail.com on 22 Jul 2010 at 7:19

GoogleCodeExporter commented 9 years ago
Noticed this issue when testing the CSLA/CodeSmith templates against the 
AdventureWorks SQL database.  The result is that the generated code does not 
compile.

The following issues cause the application not to compile due to the error: 
"Value of type 'String' cannot be converted to 'System.Xml.XmlDocument'":

1. [Entity].Generated.GetBy[XMLField] calls criteria.[XMLField] = 
[XMLField].Value when assigning the field to the criteria class.  The .Value 
causes the application not to compile.
Specifically: Contact, Individual, IndividualList, ProductModel, Store, and 
StoreList

2. [Entity]Factory.DataAccess.DoUpdate when when assigning the 
item.[XMLField].Value to temp.[XMLField] within 'Insert new child." section.  
.Value seems to be causing the problem and the application will compile if 
removed. 
- Specifically: IndividualFactory, StoreFactory

3. [Entify]Factory.DataAccess.Map calls GetString([XMLField]) which causes the 
compilation error.
- Specifically: ContactFactory, DatabaseLogFactory, IllustrationFactory, 
IndividualFactory, JobCandidateFactory, ProductModelFactory, StoreFactory

Original comment by jeremy.m...@gmail.com on 1 Jan 2011 at 9:22

GoogleCodeExporter commented 9 years ago
Xml columns are not supported. I'm not sure how they should be handled and 
passed around as an XML Document cannot be serialized. Do you think we should 
just treat this column type as a string?

Could you attach your copy of AdventureWorks DB or are you using the latest 
ones from Microsoft?

Original comment by bniemyjski on 3 Jan 2011 at 2:51

GoogleCodeExporter commented 9 years ago
Do you think we should just treat this column type as a string?

Original comment by bniemyjski on 9 Mar 2012 at 1:17

GoogleCodeExporter commented 9 years ago
Issue 643 has been merged into this issue.

Original comment by bniemyjski on 24 Apr 2012 at 1:38

GoogleCodeExporter commented 9 years ago
Yes, create as string, then have Csla check it to see it is well formed. I 
can't see any downside.

Original comment by owenbre...@msn.com on 26 Apr 2012 at 3:35

GoogleCodeExporter commented 9 years ago
Could you list the parts I have to look at? I will work on this for a few 
days...

Original comment by owenbre...@msn.com on 26 Apr 2012 at 3:38

GoogleCodeExporter commented 9 years ago
Hello,

I'm not sure where it is in the patch file off the top of my head (One of the 
reasons I asked him to split it up).  I'd recommend opening the patch file with 
svn and looking at all the changes. His changes will be highlighted (search for 
xml).

Original comment by bniemyjski on 26 Apr 2012 at 1:11

GoogleCodeExporter commented 9 years ago
the following changes will fix the fetch for XmlDocuments:

change to stored procedures:
Just one is shown
 CREATE PROCEDURE [Production].[FSP__ProductModel_Select]
    @p_ProductModelID int = NULL,
    @p_Name nvarchar(50) = NULL,
    --@p_CatalogDescription xml = NULL, changed to varchar(MAX)
    @p_CatalogDescription varchar(MAX) = NULL,
    @p_CatalogDescriptionHasValue BIT = 0,
    @p_Instructions varchar(MAX) = NULL,
    @p_InstructionsHasValue BIT = 0,
    @p_rowguid uniqueidentifier = NULL,
    @p_ModifiedDate datetime = NULL
AS

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SELECT
    [ProductModelID],
    [Name],
    [CatalogDescription],
    [Instructions],
    [rowguid],
    [ModifiedDate]
FROM
    [Production].[ProductModel]
WHERE
    ([ProductModelID] = @p_ProductModelID OR @p_ProductModelID IS NULL)
    AND ([Name] = @p_Name OR @p_Name IS NULL)
    AND ([rowguid] = @p_rowguid OR @p_rowguid IS NULL)
    AND ([ModifiedDate] = @p_ModifiedDate OR @p_ModifiedDate IS NULL)
----
For the Business Object
Add class XmlDocument:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.Schema;
namespace AdventureWorks.Business.Entities
{
   public class XmlDocument : System.Xml.XmlDocument
    {
        public Boolean HasValue;
        private string _value;
        public XmlDocument xmlValue;
        public XmlDocument() { xmlValue = new XmlDocument(); }
        public override string Value { get; set; }
        #region Constructors

        public XmlDocument(string value)
        {
            _value = value;
            xmlValue = new XmlDocument(value);
        }

        #endregion

        public XmlDocument SetXmlValue
        {
            get { return xmlValue; }
            set { xmlValue = new XmlDocument(_value); }
        }
    }

}
In the Enitities:
change  all xml criteria to string type
        public string CatalogDescription
        {
            get { return GetValue< string >("CatalogDescription"); }
            set { _bag["CatalogDescription"] = value; }
        }

Extend string to include as HasValue()

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public static class MyExtensions
{
    public static bool HasValue(this String str)
    {
        if (str == null) return false;
        else return true;

    }
}

In the entity remove all references to use the new XmlDocument:

     if(catalogDescription.HasValue()) criteria.CatalogDescription = catalogDescription;

            return DataPortal.Fetch< ProductModel >(criteria);

Original comment by owenbre...@msn.com on 26 Apr 2012 at 10:30

GoogleCodeExporter commented 9 years ago
Could you please provide a sample of this working so I could take a look.

Original comment by bniemyjski on 27 Apr 2012 at 6:34

GoogleCodeExporter commented 9 years ago
Hello,

I see that Issue 517, was updated to the latest nightly build and there is a 
updated patch for xml support as well.

Original comment by bniemyjski on 30 Apr 2012 at 1:57