Ticket Q182572
Visible to All Users

FILESTREAM and FileData

created 17 years ago

Hi
Trying to get FILESTREAM working in XAF app
I prepared the database for FILESTREAM support and tested with direct quieries.
so i have:

Code
public class BaseObject : XPCustomObject { public BaseObject(Session session) : base(session) { } [Persistent("Oid"), Key(true), Browsable(false)] private Guid oid = Guid.Empty; [PersistentAlias("oid")] [Browsable(false)] [VisibleInLookupListView(false)] public Guid Oid { get { return oid; } } [Persistent, Browsable(true), VisibleInLookupListView(false),ReadOnly(true)] public string EarthCapeID { get { return Oid.ToString("D").ToLower(); } } public override void AfterConstruction() { base.AfterConstruction(); oid = XpoDefault.NewGuid(); } }

and File data where i thought i'd decorate Content property with [DbType("VARBINARY(MAX) FILESTREAM")]

Code
public class FileData : BaseObject, IFileData, IEmptyCheckable { [Persistent] private int size; private XPDelayedProperty delayedContent = new XPDelayedProperty(); private string fileName = ""; public FileData(Session session) : base(session) { } public void LoadFromStream(string fileName, Stream stream) { FileName = fileName; byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); Content = bytes; } public void SaveToStream(Stream stream) { stream.Write(Content, 0, Size); stream.Flush(); } public void Clear() { Content = null; FileName = String.Empty; } public override string ToString() { return FileName; } [Size(260)] public string FileName { get { return fileName; } set { SetPropertyValue<string>("FileName", ref fileName, value); } } [Persistent, Delayed("delayedContent"), ValueConverter(typeof(CompressionConverter)), MemberDesignTimeVisibility(false)] [DbType("VARBINARY(MAX) FILESTREAM")] private byte[] Content { get { return (byte[])delayedContent.Value; } set { int oldSize = size; delayedContent.Value = value; if (value != null) { size = value.Length; } else { size = 0; } OnChanged("Content"); OnChanged("Size", oldSize, size); } } public int Size { get { return size; } } #region IEmptyCheckable Members [NonPersistent, MemberDesignTimeVisibility(false)] public bool IsEmpty { get { return string.IsNullOrEmpty(FileName); } } #endregion }

I get "System.Data.SqlClient.SqlException: A table with FILESTREAM column(s) must have a non-NULL unique ROWGUID column."
Whats up?
Evgeniy
PS
Maybe there is a need for XAF code sample that will include Spatial and FILESTREAM support

Show previous comments (11)
DevExpress Support Team 17 years ago

    Evgeniy,
    I couldn't reproduce the problem with your persistent class in a new project with XPO. XAF may be the cause of the problem. We are investigating it.
    Thanks,
    Nick

    Dennis Garavsky (DevExpress) 17 years ago

      Hi Evgeniy,
      I've forced this to work with XAF and our BaseObject on my machine!
      First of all, I suggest you check the following valuable article: SQL Server 2008 FILESTREAM - Part 1.
      One more article: SQL Server Storage Engine, will be helpful as well.
      The main idea is to remove the grid StreamId property from the FileData class, since we have already an unique identifier, which is actually the Oid, property that already met our needs to file stream support.
      I have attached a sample project, which works well for me.
      Thank you for your patience,
      Dennis

        Dennis, thanks again for taking time to resolve this!
        There are couple of issues though.
        I already removed StreamId column from FileData and Filestream worked fine in that sample which i stated in my post 27.8.2008 22:19:42
        After that I tried to add some code in Updater.cs (28.8.2008 9:34:26) which caused the project to crash and the reason was [DbType("uniqueidentifier UNIQUE")] - Nick said it needs investigation and it works with XPO app but something is wrong in XAF.
        So if you could test my code (from 28.8.2008 9:34:26) with the very sample you send and verify that it runs.
        Cheers,
        Evgeniy

        Answers

        created 16 years ago (modified 9 years ago)

        Hi Evgeniy,
        Sorry for the delay.
        I have solved this problem by adding a new BaseObjectForFileStreamSupport class. I used this class as a base class for the FileData class.
        Now it all works fine. I have attached a complete sample project to demonstrate this. The important files are located in the FileStreamSupport.Module project: BaseObject.cs, FileData.cs and TestDomainObject.cs.
        I am looking forward to hearing about your results.
        Thanks,
        Dennis

          Show previous comments (2)

            >>As you guess, you should not follow these requirements for other tables if you do not want file stream support there.
            >>Is any difficulty with this?
            Not at all :)
            As i see now that,
            >>XPO applies the UNIQUE attribute for the PK column some later time
            and
            >>This behavior is by design.
            which is fine by me
            Thanks
            Evgeniy

            KS KS
            kitti soongswang 9 years ago

              Hi,

              This solution was 8 years ago.  I tried to converted it to use with XAF 15.2.xx it did not work.  Please convert this example to work with XAF 15.2.xx and please provide VB example.

              Thank you.

              Dennis Garavsky (DevExpress) 9 years ago

                @kitti soongswang: I've created a separate ticket on your behalf (Questions on FileStream (Q182572)). It has been placed in our processing queue and will be answered shortly.

                Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.