数据库字段命名谁说了算
[ 2009-07-15 20:58:35 | 作者: progame ]
数据库命名现在有很多种,假如有Customer 表, Name字段
有customer_name, name, customername, 当然用中文或拼音的直接无视好了
表命名,有customer, customers,xxCustomer, xx_Customer这样这种,xx为模块命名
从单纯ORM映射来讲,customer和name是最直接好用的,但是Linq出来之后,问题来了
假如你join两个表,查询生成一个结果集,就会出现字段重名,于是你只好
select new{customername = customer.name, cityname = customer.city.name}
所以为了Linq的方便join,推荐使用CustomerName命名方式
这样便方便了
select new{customer.customername,customer.city.cityname}
同时,给直接写sql也带来了更好的可辨识度,如
from customer a left join city b on a.citycode = b.citycode
而表命名,表少时,直接用customer比较好,但是当你有几百上千个表时,加模块前缀就是非常有用的
包括数据库维护时定位表也是有帮助的,尤其是你需要数据同步,要选表发布时就知道好处了
有customer_name, name, customername, 当然用中文或拼音的直接无视好了
表命名,有customer, customers,xxCustomer, xx_Customer这样这种,xx为模块命名
从单纯ORM映射来讲,customer和name是最直接好用的,但是Linq出来之后,问题来了
假如你join两个表,查询生成一个结果集,就会出现字段重名,于是你只好
select new{customername = customer.name, cityname = customer.city.name}
所以为了Linq的方便join,推荐使用CustomerName命名方式
这样便方便了
select new{customer.customername,customer.city.cityname}
同时,给直接写sql也带来了更好的可辨识度,如
from customer a left join city b on a.citycode = b.citycode
而表命名,表少时,直接用customer比较好,但是当你有几百上千个表时,加模块前缀就是非常有用的
包括数据库维护时定位表也是有帮助的,尤其是你需要数据同步,要选表发布时就知道好处了
分类: WPF/SilverLight |
评论: 2 |
浏览: 306
[转] Convert a LINQ Query Resultset to a DataTable [私人]
[ 2009-04-13 15:19:27 | 作者: progame ]
Convert a LINQ Query Resultset to a DataTable
After a long struggle I find out the way to convert a Linq Query resultset to DataTable object. The attached source code shows how to do it. I am sharing this article with my developer friends and make their life easier.
Here are two samples.
Sample I:
I created a public method called LINQToDataTable as following:
public DataTable LINQToDataTable<T>(IEnumerable<T> varlist)
{
DataTable dtReturn = new DataTable();
// column names
PropertyInfo[] oProps = null;
if (varlist == null) return dtReturn;
foreach (T rec in varlist)
{
// Use reflection to get property names, to create table, Only first time, others
will follow
if (oProps == null)
{
oProps = ((Type)rec.GetType()).GetProperties();
foreach (PropertyInfo pi in oProps)
{
Type colType = pi.PropertyType;
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()
==typeof(Nullable<>)))
{
colType = colType.GetGenericArguments()[0];
}
dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
}
}
DataRow dr = dtReturn.NewRow();
foreach (PropertyInfo pi in oProps)
{
dr[pi.Name] = pi.GetValue(rec, null) == null ?DBNull.Value :pi.GetValue
(rec,null);
}
dtReturn.Rows.Add(dr);
}
return dtReturn;
}
---------------------------------------------------------------
Example: To use this method, just use the following code sample:
---------------------------------------------------------------
var vrCountry = from country in objEmpDataContext.CountryMaster
...
阅读全文...
After a long struggle I find out the way to convert a Linq Query resultset to DataTable object. The attached source code shows how to do it. I am sharing this article with my developer friends and make their life easier.
Here are two samples.
Sample I:
I created a public method called LINQToDataTable as following:
public DataTable LINQToDataTable<T>(IEnumerable<T> varlist)
{
DataTable dtReturn = new DataTable();
// column names
PropertyInfo[] oProps = null;
if (varlist == null) return dtReturn;
foreach (T rec in varlist)
{
// Use reflection to get property names, to create table, Only first time, others
will follow
if (oProps == null)
{
oProps = ((Type)rec.GetType()).GetProperties();
foreach (PropertyInfo pi in oProps)
{
Type colType = pi.PropertyType;
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()
==typeof(Nullable<>)))
{
colType = colType.GetGenericArguments()[0];
}
dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
}
}
DataRow dr = dtReturn.NewRow();
foreach (PropertyInfo pi in oProps)
{
dr[pi.Name] = pi.GetValue(rec, null) == null ?DBNull.Value :pi.GetValue
(rec,null);
}
dtReturn.Rows.Add(dr);
}
return dtReturn;
}
---------------------------------------------------------------
Example: To use this method, just use the following code sample:
---------------------------------------------------------------
var vrCountry = from country in objEmpDataContext.CountryMaster
...
阅读全文...
分类: WPF/SilverLight |
评论: 0 |
浏览: 208
[转]Securing Silverlight Application and WCF Service using ASP.Net Authentication Techniques [私人]
[ 2009-04-05 23:36:45 | 作者: progame ]
Securing Silverlight Application and WCF Service using ASP.Net Authentication Techniques
January 7, 2009 — Syed Mehroz Alam
Ads by Google
WPF Controls & Consulting
For Designers and Developers by the leading WPF experts - IdentityMine
www.blendables.com
Security is an issue that experts are discussing since the birth of Silverlight. A typical enterprise Silverlight application will consist of one or more Silverlight pages communicating with one or more WCF services. There are three major security concerns here:
Silverlight 2 supports communication with a WCF service in simple text (the basicHttpBinding), so anyone can use a packet sniffer (e.g. Fiddler) to read our data.
Anyone can access our WCF service, call its methods and get our data.
Anyone can download our Silverlight application (the .xap file), open it (since it is simple a zip file), extract the dlls and use Reflector to read all our code.
The first problem can be solved by securing the transmission via transport security (using https protocol). More on this can be found at msdn here. In this post, I will try to address the last two issues.
The good thing is that the Silverlight application and WCF service is hosted inside an ASP.NET website and luckily ASP.NET provides good tools around authentication so we can apply ASP.NET authentication techniques to secure those. The approach I like is to secure the entire ASP.NET web application using either Windows or Forms authentication and deny all anonymous users. This can be done by configuring the web.config as:
view plaincopy to clipboardprint?
<authentication mode="Windows"/> <!-- or Forms -->
<authorization>
<deny users="?"/>
</authorization>
<authentication mode="Windows"/> <!-- or Forms -->
<authorization>
<deny users="?"/>
</authorization>
This way, if anyone tries to access ...
阅读全文...
January 7, 2009 — Syed Mehroz Alam
Ads by Google
WPF Controls & Consulting
For Designers and Developers by the leading WPF experts - IdentityMine
www.blendables.com
Security is an issue that experts are discussing since the birth of Silverlight. A typical enterprise Silverlight application will consist of one or more Silverlight pages communicating with one or more WCF services. There are three major security concerns here:
Silverlight 2 supports communication with a WCF service in simple text (the basicHttpBinding), so anyone can use a packet sniffer (e.g. Fiddler) to read our data.
Anyone can access our WCF service, call its methods and get our data.
Anyone can download our Silverlight application (the .xap file), open it (since it is simple a zip file), extract the dlls and use Reflector to read all our code.
The first problem can be solved by securing the transmission via transport security (using https protocol). More on this can be found at msdn here. In this post, I will try to address the last two issues.
The good thing is that the Silverlight application and WCF service is hosted inside an ASP.NET website and luckily ASP.NET provides good tools around authentication so we can apply ASP.NET authentication techniques to secure those. The approach I like is to secure the entire ASP.NET web application using either Windows or Forms authentication and deny all anonymous users. This can be done by configuring the web.config as:
view plaincopy to clipboardprint?
<authentication mode="Windows"/> <!-- or Forms -->
<authorization>
<deny users="?"/>
</authorization>
<authentication mode="Windows"/> <!-- or Forms -->
<authorization>
<deny users="?"/>
</authorization>
This way, if anyone tries to access ...
阅读全文...
分类: WPF/SilverLight |
评论: 0 |
浏览: 154
1

