Linq to Sql +自定义数据类型

时间:2021-04-12 16:23:03

I have a custom asp.net control i created that allows you to bind an object to it, it functions kinda like a winform propertygrid.

我创建了一个自定义的asp.net控件,允许您将对象绑定到它,它的功能类似于winform propertygrid。

Heres my issue: the control looks at the public properties and types of the class, if it detects a type of color it renders a color picker, etc.. Works great for classes that i create - however not so well when using an entity from link since its public properties are primitive types (int, string, bool).

继承人我的问题:控件查看类的公共属性和类型,如果它检测到颜色类型它呈现颜色选择器等等。适用于我创建的类 - 但是当使用实体时不太好链接,因为它的公共属性是原始类型(int,string,bool)。

I created a custom data type in sql2005 called color and i was hoping that it would carry over to the entity created by linq, but it sees it as its underlying type which is System.String

我在sql2005中创建了一个名为color的自定义数据类型,我希望它可以继承到linq创建的实体,但是它将它视为它的基础类型,即System.String

So, how do i create my entity types but have .NET see other types? Can i change the type before i return it to the caller?

那么,我如何创建我的实体类型,但让.NET看到其他类型?我可以在将其返回给调用者之前更改类型吗?

ie:

public IEnumerable<SomeObject> GetSomething()
{
   MyEntity entity = new MyEntity("constr");
   var a = blahblah...;

   // Modify the types here?
   return a;

}

1 个解决方案

#1


On the LinqToSQL Designer you can change the property type of a field. Have you tried changing that?

在LinqToSQL Designer上,您可以更改字段的属性类型。你试过改变吗?

You might also be able to write a partial class of that class and include a convert function that switches it to the correct type (IConvertable maybe?).

您也可以编写该类的部分类,并包含一个转换函数,将其切换为正确的类型(IConvertable可能?)。

#1


On the LinqToSQL Designer you can change the property type of a field. Have you tried changing that?

在LinqToSQL Designer上,您可以更改字段的属性类型。你试过改变吗?

You might also be able to write a partial class of that class and include a convert function that switches it to the correct type (IConvertable maybe?).

您也可以编写该类的部分类,并包含一个转换函数,将其切换为正确的类型(IConvertable可能?)。