开发者

How to create separate file ( .vb or .cs ) for each table in db using subsonic 3.0

开发者 https://www.devze.com 2023-02-18 18:30 出处:网络
i am using subsonic v.3 to generate my DAL layer in my ASP.NET application with VB.NET(.NET framework 3.5).

i am using subsonic v.3 to generate my DAL layer in my ASP.NET application with VB.NET(.NET framework 3.5). i have used the subsonic v.2 and i which it was creating a separate .cs file for each table and event each class file has on method called LoadByParam() or LoadByKey() in case if one want to load the object by passing some field value.

but in subsonic 3 when i add core file and add T4 template in my project it's generating three vb file named activrecord.vb , context.vb and struct.vb

I want to know how can i load all the table in separate file as in subsonic how to load a database object by passing some field as a filed i.e in subsonic 2.0 when i want to load user table with some give id i was loading it this way new myProject.user(column-name, filed-value); how can i开发者_高级运维 achieve the same with subsonic 3.0 ??


If you ask me, I would add a c# class library to your project and use for your DAL, since the c# have a broader userbase and are thus more tested. VB and C# work perfectly together in a Solution

This said, the latest c# templates already create seperate files: https://github.com/subsonic/SubSonic-3.0-Templates/tree/master/ActiveRecord

I suppose nobody migrated the code to vb.net atm.

Regarding your second question (how to load an object by columnname), subsonic 3 makes heavy use of lambda expressions, so you only need to use the overload that takes an Expression(of Func(of User, Boolean))

In other words:

dim user1 as new User(Function(x) x.UserName = "Test")

or

dim user2 as User = User.SingleOrDefault(Function(x) x.UserName = "Test")

or even

dim user3 as User = (From u in User.All()
                     Where u.UserName = "Test"
                     Select u).SingleOrDefault()

the last two return a User object or Nothing. The first always returns an object, even if the user does not exist, so you have to check user1.IsNew() if needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号