This question is locked. New answers and comments are not allowed.
I have a method like this:
public void CreateAndAddTagToElement(string tag, string tagType, Guid elementId, float weight) {
if (Log.IsDebugEnabled) {
Log.Debug("CreateAndAddTagToElement Start");
}
Guid guid = Guid.NewGuid();
try
{
Tag newTag = new Tag();
newTag.Created = DateTime.Now;
newTag.CreatedBy = "Madman";
newTag.TagId = guid;
newTag.TagType = tagType;
TagContent tagContent = new TagContent();
tagContent.TagContentId = Guid.NewGuid();
tagContent.Tag = newTag;
tagContent.TagData = tag;
tagContent.Created = DateTime.Now;
tagContent.CreatedBy = "Madman";
tagContent.CultureName = "en";
using (IObjectScope scope = PhoenixObjectScopeProvider.GetNewObjectScope())
{
scope.Transaction.Begin();
scope.Add(newTag);
scope.Add(tagContent);
scope.Transaction.Commit();
}
}
catch (Telerik.OpenAccess.Exceptions.DataStoreException dse) {
Log.Error("CreateAndAddTagToElement DataStoreException.", dse);
}
}
When this code runs I always get a fk error. Profiling using sql profiler while the code runs shows these statements being executed:
declare @p1 int
set @p1=1
exec sp_prepexec @p1 output,N'@p0 datetime,@p1 nvarchar(255),@p2 uniqueidentifier,@p3 nvarchar(60)',N'INSERT INTO [KBS].[TAG] ([CREATED], [CREATED_BY], [TAG_ID], [TAG_TYPE]) VALUES (@p0, @p1, @p2, @p3)',@p0='2009-10-08 15:14:11.9870000',@p1=N'Madman',@p2='8CA1C327-3BF9-4A5D-96E8-ADF455DF00AF',@p3=N'Group'
select @p1
declare @p1 int
set @p1=2
exec sp_prepexec @p1 output,N'@p0 datetime,@p1 nvarchar(255),@p2 nvarchar(10),@p3 uniqueidentifier,@p4 nvarchar(60),@p5 uniqueidentifier',N'INSERT INTO [KBS].[TAG_CONTENT] ([CREATED], [CREATED_BY], [CULTURE_NAME], [TAG_CONTENT_ID], [TAG_DATA], [TAG_ID]) VALUES (@p0, @p1, @p2, @p3, @p4, @p5)',@p0='2009-10-08 15:14:11.9900000',@p1=N'Madman',@p2=N'en',@p3='398AF7DD-F075-4B9D-95AB-5889F6A09D81',@p4=N'1newtag',@p5='00000000-0000-0000-0000-000000000000'
select @p1
As you can see TAG_ID in the second call is an empty guid, not the guid that was set on the tag in code. What am I doing wrong here?
Thanks,
Adam
public void CreateAndAddTagToElement(string tag, string tagType, Guid elementId, float weight) {
if (Log.IsDebugEnabled) {
Log.Debug("CreateAndAddTagToElement Start");
}
Guid guid = Guid.NewGuid();
try
{
Tag newTag = new Tag();
newTag.Created = DateTime.Now;
newTag.CreatedBy = "Madman";
newTag.TagId = guid;
newTag.TagType = tagType;
TagContent tagContent = new TagContent();
tagContent.TagContentId = Guid.NewGuid();
tagContent.Tag = newTag;
tagContent.TagData = tag;
tagContent.Created = DateTime.Now;
tagContent.CreatedBy = "Madman";
tagContent.CultureName = "en";
using (IObjectScope scope = PhoenixObjectScopeProvider.GetNewObjectScope())
{
scope.Transaction.Begin();
scope.Add(newTag);
scope.Add(tagContent);
scope.Transaction.Commit();
}
}
catch (Telerik.OpenAccess.Exceptions.DataStoreException dse) {
Log.Error("CreateAndAddTagToElement DataStoreException.", dse);
}
}
When this code runs I always get a fk error. Profiling using sql profiler while the code runs shows these statements being executed:
declare @p1 int
set @p1=1
exec sp_prepexec @p1 output,N'@p0 datetime,@p1 nvarchar(255),@p2 uniqueidentifier,@p3 nvarchar(60)',N'INSERT INTO [KBS].[TAG] ([CREATED], [CREATED_BY], [TAG_ID], [TAG_TYPE]) VALUES (@p0, @p1, @p2, @p3)',@p0='2009-10-08 15:14:11.9870000',@p1=N'Madman',@p2='8CA1C327-3BF9-4A5D-96E8-ADF455DF00AF',@p3=N'Group'
select @p1
declare @p1 int
set @p1=2
exec sp_prepexec @p1 output,N'@p0 datetime,@p1 nvarchar(255),@p2 nvarchar(10),@p3 uniqueidentifier,@p4 nvarchar(60),@p5 uniqueidentifier',N'INSERT INTO [KBS].[TAG_CONTENT] ([CREATED], [CREATED_BY], [CULTURE_NAME], [TAG_CONTENT_ID], [TAG_DATA], [TAG_ID]) VALUES (@p0, @p1, @p2, @p3, @p4, @p5)',@p0='2009-10-08 15:14:11.9900000',@p1=N'Madman',@p2=N'en',@p3='398AF7DD-F075-4B9D-95AB-5889F6A09D81',@p4=N'1newtag',@p5='00000000-0000-0000-0000-000000000000'
select @p1
As you can see TAG_ID in the second call is an empty guid, not the guid that was set on the tag in code. What am I doing wrong here?
Thanks,
Adam