亚音速生成的DB模式,二进制类型? [英] SubSonic generated DB Schema, binary types?

查看:289
本文介绍了亚音速生成的DB模式,二进制类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何使用亚音速的架构构建在创建数据库二进制列?

How do you create binary columns in the DB using SubSonic's Schema builder?

所以,今晚我决定潜入亚音速。我看到很多的罗布和许多其他的问题在这里和伟大的反应。我看到亚音速是一个ORM,用T4模板可以从现有的数据库中的一些很不错的,高效的类。

So tonight I decided to dive into SubSonic. I see a lot of questions on here and great responses by Rob and many others. I see that SubSonic is an ORM, with the T4 Templates it can generate some very nice and efficient classes from an existing database.

不过,我希望走另一条路。我有一个非常丰富的域名,并希望用亚音速从我的域名创建我的表即席和RunMigrations选项。

But, I want to go the other way. I have a very rich Domain, and want to create my tables adhoc from my Domain using SubSonic and the RunMigrations option.

所有的作品非常好(甚至写我自己升级(检测是否该代码库具有基于大会版本号的变化,然后)功能迁移所有对象更新到数据库 - 非常漂亮和有效的为自动升级DB)

All works extremely well (even wrote my own Upgrade() function that detects if the codebase has changes based on the Assembly revision number, and then migrates all object updates to the DB - pretty slick and efficent for auto-upgrading the DB).

但是,你怎么有亚音速创建二进制列?也许我不会把它当成目的(我不使用查询或SqlQuery类,只是SimpleRepository的LINQ的接口)。见下面(使用一个共同的博文为例):

But, how do you have SubSonic create binary columns? Maybe I am not using it as intended (I am not using Query or SqlQuery, just the Linq interface of SimpleRepository). See below (using a common "Blog Post" example):

[SubsonicTable]
public class Post
{
	[SubSonicPrimaryKey]
	public Int32 PostID { get; set; }

	[SubSonicStringLength(1024)]
	public String Title { get; set; }

	[SubSonicLongString]
	public String Body { get; set; }

	[SubSonicStringLength(5)]
	public String? LangaugeCode { get; set; }

	public DateTime? Published { get; set; }

	public PostType PostType { get; set; }
	public Int32 PostTypeID
	{
		get
		{
			return this.PostType.GetHashCode();
		}
		set
		{
			Enum.Parse(typeof(PostType), value.ToString());
		}
	}

	public Byte[] Image { get; set; }
}

public enum PostType
{
	NotSet = 0
	,BlogPost
	,Comment
	,Trackback
	,Pingback
}

在这个帖子对象被保存,或查询,通过SimpleRepository ,它缺少两列:PostType(或枚举类型PostType)和图像(类型为byte []数组)

When this Post object gets saved, or queried, via the SimpleRepository, it is missing two columns: PostType (or type enum PostType) and Image (of type byte[] array).

现在,我发现下锅的安-answer这里有人张贴了关于使用的Int32 PostTypeID避开枚举问题。快来抢,亚音速应该能够支持枚举类型INT,并从他们回来。 ;)这就是为什么我有PostTypeID,这被创建并写入正确

Now, I found the hack-of-an-answer here that someone posted about using an Int32 PostTypeID to get around the enum issue. Come on Rob, SubSonic should be able to support enum types to INT, and back from them. ;) This is why I have the PostTypeID, and this gets created and written properly.

下面是我创建邮报表的命令,示例以及插入的第一篇文章:

Here's an example of the command that creates the Post table for me, as well as inserting the first post:

Post p = new Post();
p.Title = "My Title";
p.Body = "The body of the post.";
p.PostType = PostType.BlogPost;

var repo = new SimpleRepository(SimpleRepositoryOptions.RunMigrations);
repo.Add(p);

请注意:你不应该在生产中使用此代码,因为RunMigrations有很多额外TSQL查询第一次运行。

NOTE: You should not use this code in production, as the RunMigrations has lots of additional TSQL queries at first run.

您可以通过上面的例子看,这将创建的帖子表,如果它不存在,以及创建列。

You can see by the example above that this will create the Posts table if it doesn't exist, as well as creating the columns.

但是,这不会产生上面提到的两列:PostType也不图像

But, this does not create the two columns mentioned above: PostType nor Image.

的思考?而在此先感谢

推荐答案

我的认为的,我们有一个二进制的嗅探器 - 原来它doesn 'T做的伎俩。我需要补充这一点 - 更好的是,如果你不介意分叉我们所拥有的,加入这个 - 我爱你。以一个战利品我们扩展的东西 - 你想modToDataTable()(我认为)...

I had thought we had a binary sniffer - turns out it doesn't do the trick. I need to add this - better yet if you wouldn't mind forking what we have and adding this - I'd love you for it. Take a loot at our Extensions stuff - you want to mod ToDataTable() (I think)...

如果你没有得到一个机会 - 我来补充这个时候我加快转速SimpleRepo下一...

If you don't get a chance - I'll add this when I rev up SimpleRepo next...

这篇关于亚音速生成的DB模式,二进制类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆