我正在尝试开发CodeFluent方面,将实体的属性设置为全文索引。
我找到了这个链接,它的功能类似于我的目标。
migrate
但是,它使用SQL模板生成器。无论如何都要将属性设置为完全在方面本身的全文索引,所以我不必为所有项目安装/维护模板生成器和方面?
这是我到目前为止的C#方面代码:
Cannot convert type 'CodeFluent.Model.Producer' to 'CodeFluent.Producers.SqlServer.TemplateProducer'
编辑一个:
在Meziantou的回答之后,我试图创建一个模板生成器,但当我尝试将新的模板生成器添加到项目生成器列表时,它给了我编译错误,所以我和#39;我可能做错了。
错误说:
public XmlDocument Run(IDictionary context)
{
if (context == null || !context.Contains("Project"))
{
// we are probably called for meta data inspection, so we send back the descriptor xml
return Descriptor;
}
// the dictionary contains at least these two entries
XmlElement element = (XmlElement)context["Element"];
Project project = (Project)context["Project"];
CodeFluent.Producers.SqlServer.TemplateProducer producer = new CodeFluent.Producers.SqlServer.TemplateProducer();
producer.AddNamespace("CodeFluent.Model");
producer.AddNamespace("CodeFluent.Model.Persistence");
producer.AddNamespace("CodeFluent.Producers.SqlServer");
Console.WriteLine(producer.Element);
//TODO: Need to figure out how to modify the actual template's contents
project.Producers.Add(producer); //Error happens here
// we have no specific Xml to send back, but aspect description
return Descriptor;
}
这是我到目前为止的代码:
zip
答案 0 :(得分:0)
在示例代码中,仅使用方面,因为它具有描述符。 CodeFluent实体使用描述符来填充属性网格:
<cf:descriptor name="IsClusteredIndex" typeName="boolean" targets="Property" defaultValue="false" displayName="IsClusteredIndex" />
因此,当您将此属性的值设置为true或false时,会在xml文件中添加或删除xml属性ns:IsClusteredIndex
。
然后,SQL模板读取属性的值以生成预期的SQL文件:
property.GetAttributeValue("sa:IsClusteredIndex", false)
因此,方面不是强制性的,但提供了一种添加/删除属性的图形界面友好方式。如果您不需要集成到图形界面,则可以安全地删除该方面。
如果您的目标是集成到图形界面,则需要一个方面(XML或DLL)或生产者。如果您不想创建生产者,可以将模板嵌入到您的方面。在构建期间,您可以提取SQL模板并将SQL模板生成器添加到项目中,这样一切都位于方面。