views:

103

answers:

1

Hi, By virtue of my application, I need to seperate my business entities from the entities created by EF4. I need to restrict the entities to only access the repository from where they are translated (using translator) to business entities shared at business and service layer. I thought of restricting them by specifying them as internal. Now there are more than 40 entities in my application so manually setting them as internal is a difficult job. In one of the forums the answers suggested using the T4 templates. But even those templates read from the entity framework access specifier. When I try to manually try to specify all the properties and class access specifiers as internal it gives me an error saying that the entity set should also be set to internal, but there is no option for the same. I am using VS 2010 and Entity Framework 4. Any suggestions???

A: 

It's difficult to do a search and replace with a regex? Right click your EDMX, open as XML, and press Ctrl+H.

An example search string is:

\<EntityType:b{.+}\>

An example replace string is:

\<EntityType \1 a:TypeAccess="Private" xmlns:a="http://schemas.microsoft.com/ado/2006/04/codegeneration" \>

For simplicity, I haven't detected existing TypeAccess. You can make the regex as complicated as you like.

You have to check the box to tell VS to use the regex.

Craig Stuntz
Whenever any entity is defined as public or default access specifier, no attributes are mentioned. Only if the access specifier is changed, the attributes are added. So search and replace also won't work
Vedaantees
Of course it will work. Search for names which don't already have a visibility specifier. You can do this with a regex and capturing groups. Alternately, use XSLT if you're more comfortable with that.
Craig Stuntz
can you give an example for regex?
Vedaantees
Um, OK, I added a regex example. There are regex examples all over the net, you know....
Craig Stuntz